@Override public Block build() { if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, positionCount); } return new ByteArrayBlock(0, positionCount, hasNullValue ? valueIsNull : null, values); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new ByteArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new byte[] {values[position + arrayOffset]}); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new ByteArrayBlock(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]; } byte[] newValues = new byte[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 ByteArrayBlock(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 : Byte.BYTES; }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); boolean[] newValueIsNull = null; if (valueIsNull != null) { newValueIsNull = new boolean[length]; } byte[] newValues = new byte[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 ByteArrayBlock(0, length, newValueIsNull, newValues); }
@Override public byte getByte(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("ByteArrayBlock{"); sb.append("positionCount=").append(getPositionCount()); sb.append('}'); return sb.toString(); }
@Override public long getEstimatedDataSizeForStats(int position) { return isNull(position) ? 0 : Byte.BYTES; }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new ByteArrayBlock( 0, 1, valueIsNull[position] ? new boolean[] {true} : null, new byte[] {values[position]}); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); positionOffset += arrayOffset; boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, positionOffset, length); byte[] newValues = compactArray(values, positionOffset, length); if (newValueIsNull == valueIsNull && newValues == values) { return this; } return new ByteArrayBlock(0, length, newValueIsNull, newValues); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); return new ByteArrayBlock( 0, 1, isNull(position) ? new boolean[] {true} : null, new byte[] {values[position + arrayOffset]}); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { checkReadablePosition(position); blockBuilder.writeByte(values[position + arrayOffset]); blockBuilder.closeEntry(); }
private void checkReadablePosition(int position) { if (position < 0 || position >= getPositionCount()) { throw new IllegalArgumentException("position is not valid"); } } }
@Override public Block toBlock(Type desiredType) { checkArgument(BOOLEAN.equals(desiredType), "type doesn't match: %s", desiredType); int numberOfRecords = numberOfRecords(); return new ByteArrayBlock( numberOfRecords, Optional.ofNullable(nulls), booleans == null ? new byte[numberOfRecords] : toByteArray(booleans)); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); return new ByteArrayBlock(positionOffset + arrayOffset, length, valueIsNull, values); }
@Override public boolean isNull(int position) { checkReadablePosition(position); return valueIsNull != null && valueIsNull[position + arrayOffset]; }
@Override public String toString() { StringBuilder sb = new StringBuilder("ByteArrayBlock{"); sb.append("positionCount=").append(getPositionCount()); sb.append('}'); return sb.toString(); }