@Override public Block build() { if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); } return new IntArrayBlock(0, positionCount, hasNullValue ? valueIsNull : null, values); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new IntArrayBlock( 0, 1, valueIsNull[position] ? new boolean[] {true} : null, new int[] {values[position]}); }
@Override public Block toBlock(Type desiredType) { checkArgument(INTEGER.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new IntArrayBlock( numberOfRecords, Optional.ofNullable(nulls), ints == null ? new int[numberOfRecords] : ints); }
@Override public Block toBlock(Type desiredType) { checkArgument(DATE.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new IntArrayBlock( numberOfRecords, Optional.ofNullable(nulls), dates == null ? new int[numberOfRecords] : dates); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new IntArrayBlock(positionOffset + arrayOffset, length, valueIsNull, values); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new IntArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new int[] {values[position + arrayOffset]}); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } boolean[] newValueIsNull = null; if (hasNullValue) { newValueIsNull = Arrays.copyOfRange(valueIsNull, positionOffset, positionOffset + length); } int[] newValues = Arrays.copyOfRange(values, positionOffset, positionOffset + length); return new IntArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput) { int positionCount = sliceInput.readInt(); boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null); int[] values = new int[positionCount]; for (int position = 0; position < positionCount; position++) { if (valueIsNull == null || !valueIsNull[position]) { values[position] = sliceInput.readInt(); } } return new IntArrayBlock(0, positionCount, valueIsNull, values); } }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); boolean[] newValueIsNull = null; if (valueIsNull != null) { newValueIsNull = new boolean[length]; } int[] newValues = new int[length]; for (int i = 0; i < length; i++) { int position = positions[offset + i]; checkReadablePosition(position); if (valueIsNull != null) { newValueIsNull[i] = valueIsNull[position + arrayOffset]; } newValues[i] = values[position + arrayOffset]; } return new IntArrayBlock(0, length, newValueIsNull, newValues); }
@Test public void testCompactBlock() { int[] intArray = {0, 0, 1, 2, 3, 4}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new IntArrayBlock(0, Optional.empty(), new int[0])); testCompactBlock(new IntArrayBlock(intArray.length, Optional.of(valueIsNull), intArray)); testIncompactBlock(new IntArrayBlock(intArray.length - 1, Optional.of(valueIsNull), intArray)); }
@Test public void testCompactBlock() { int[] intArray = {0, 0, 1, 2, 3, 4}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new IntArrayBlock(0, Optional.empty(), new int[0])); testCompactBlock(new IntArrayBlock(intArray.length, Optional.of(valueIsNull), intArray)); testIncompactBlock(new IntArrayBlock(intArray.length - 1, Optional.of(valueIsNull), intArray)); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new IntArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); int[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new IntArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } boolean[] newValueIsNull = null; if (hasNullValue) { newValueIsNull = new boolean[length]; } int[] newValues = new int[length]; for (int i = 0; i < length; i++) { int position = positions[offset + i]; checkReadablePosition(position); if (hasNullValue) { newValueIsNull[i] = valueIsNull[position]; } newValues[i] = values[position]; } return new IntArrayBlock(0, length, newValueIsNull, newValues); }