@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 getSingleValueBlock(int position) { checkReadablePosition(position); return new LongArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new long[] {values[position + arrayOffset]}); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new LongArrayBlock(positionOffset + arrayOffset, length, 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 boolean isNull(int position) { checkReadablePosition(position); return valueIsNull != null && valueIsNull[position + arrayOffset]; }
private void checkReadablePosition(int position) { if (position < 0 || position >= getPositionCount()) { throw new IllegalArgumentException("position is not valid"); } } }
@Override public long getEstimatedDataSizeForStats(int position) { return isNull(position) ? 0 : Long.BYTES; }
@Override public long getLong(int position, int offset) { checkReadablePosition(position); if (offset != 0) { throw new IllegalArgumentException("offset must be zero"); } return values[position + arrayOffset]; }
@Override public String toString() { StringBuilder sb = new StringBuilder("LongArrayBlock{"); sb.append("positionCount=").append(getPositionCount()); sb.append('}'); return sb.toString(); }
@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 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 @Deprecated // TODO: Remove when we fix intermediate types on aggregations. public int getInt(int position, int offset) { checkReadablePosition(position); if (offset != 0) { throw new IllegalArgumentException("offset must be zero"); } return toIntExact(values[position + arrayOffset]); }
@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 @Deprecated // TODO: Remove when we fix intermediate types on aggregations. public short getShort(int position, int offset) { checkReadablePosition(position); if (offset != 0) { throw new IllegalArgumentException("offset must be zero"); } short value = (short) (values[position + arrayOffset]); if (value != values[position + arrayOffset]) { throw new ArithmeticException("short overflow"); } return value; }
@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 @Deprecated // TODO: Remove when we fix intermediate types on aggregations. public byte getByte(int position, int offset) { checkReadablePosition(position); if (offset != 0) { throw new IllegalArgumentException("offset must be zero"); } byte value = (byte) (values[position + arrayOffset]); if (value != values[position + arrayOffset]) { throw new ArithmeticException("byte overflow"); } return value; }
@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 void writePositionTo(int position, BlockBuilder blockBuilder) { checkReadablePosition(position); blockBuilder.writeLong(values[position + arrayOffset]); blockBuilder.closeEntry(); }
@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); } }