@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new LongArrayBlock( 0, 1, valueIsNull[position] ? new boolean[] {true} : null, new long[] {values[position]}); }
@Override public Block build() { if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); } return new LongArrayBlock(0, positionCount, hasNullValue ? valueIsNull : null, values); }
@Override public Block toBlock(Type desiredType) { checkArgument(TIMESTAMP.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new LongArrayBlock( numberOfRecords, Optional.ofNullable(nulls), timestamps == null ? new long[numberOfRecords] : timestamps); }
@Override public Block toBlock(Type desiredType) { checkArgument(BIGINT.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new LongArrayBlock( numberOfRecords, Optional.ofNullable(nulls), longs == null ? new long[numberOfRecords] : longs); }
@Override public Block toBlock(Type desiredType) { checkArgument(DOUBLE.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); long[] longs = new long[numberOfRecords]; if (doubles != null) { for (int i = 0; i < numberOfRecords; i++) { longs[i] = doubleToLongBits(doubles[i]); } } return new LongArrayBlock( numberOfRecords, Optional.ofNullable(nulls), longs); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new LongArrayBlock(positionOffset + arrayOffset, length, valueIsNull, values); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new LongArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new long[] {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); } long[] newValues = Arrays.copyOfRange(values, positionOffset, positionOffset + length); return new LongArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput) { int positionCount = sliceInput.readInt(); boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null); long[] values = new long[positionCount]; for (int position = 0; position < positionCount; position++) { if (valueIsNull == null || !valueIsNull[position]) { values[position] = sliceInput.readLong(); } } return new LongArrayBlock(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]; } long[] newValues = new long[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 LongArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block toBlock(Type desiredType) { checkArgument(desiredType.getTypeParameters().size() == 1 && BIGINT.equals(desiredType.getTypeParameters().get(0)), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return ArrayBlock.fromElementBlock( numberOfRecords, Optional.of(nulls == null ? new boolean[numberOfRecords] : nulls), calculateOffsets(sizes, nulls, numberOfRecords), values != null ? values.toBlock(BIGINT) : new LongArrayBlock(0, Optional.empty(), new long[] {})); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new LongArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Test public void testCompactBlock() { long[] longArray = {0L, 0L, 1L, 2L, 3L, 4L}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new LongArrayBlock(0, Optional.empty(), new long[0])); testCompactBlock(new LongArrayBlock(longArray.length, Optional.of(valueIsNull), longArray)); testIncompactBlock(new LongArrayBlock(longArray.length - 1, Optional.of(valueIsNull), longArray)); }
@Test public void testCompactBlock() { long[] longArray = {0L, 0L, 1L, 2L, 3L, 4L}; boolean[] valueIsNull = {false, true, false, false, false, false}; testCompactBlock(new LongArrayBlock(0, Optional.empty(), new long[0])); testCompactBlock(new LongArrayBlock(longArray.length, Optional.of(valueIsNull), longArray)); testIncompactBlock(new LongArrayBlock(longArray.length - 1, Optional.of(valueIsNull), longArray)); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); long[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new LongArrayBlock(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]; } long[] newValues = new long[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 LongArrayBlock(0, length, newValueIsNull, newValues); }
assertEquals(functionImplementation.getAllChoices().get(0).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(USE_NULL_FLAG))); assertEquals(functionImplementation.getAllChoices().get(1).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(BLOCK_AND_POSITION))); Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]); Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]); assertFalse((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0)); functionImplementation = function.specialize(LONG_DECIMAL_BOUND_VARIABLES, 2, TYPE_REGISTRY, REGISTRY);
assertEquals(functionImplementation.getAllChoices().get(0).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(USE_NULL_FLAG))); assertEquals(functionImplementation.getAllChoices().get(1).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(BLOCK_AND_POSITION))); Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]); Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]); assertFalse((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0)); functionImplementation = function.specialize(LONG_DECIMAL_BOUND_VARIABLES, 2, TYPE_REGISTRY, REGISTRY);