@Override public void writeBytesTo(int position, int offset, int length, BlockBuilder blockBuilder) { checkReadablePosition(position); blockBuilder.writeBytes(getRawSlice(), valueOffset(position) + offset, length); }
protected void checkReadablePosition(int position) { if (position < 0 || position >= getPositionCount()) { throw new IllegalArgumentException("position is not valid"); } } }
@Override public boolean isNull(int position) { checkReadablePosition(position); return isEntryNull(position); }
@Override public long hash(int position, int offset, int length) { checkReadablePosition(position); if (isNull(position)) { return 0; } return XxHash64.hash(getRawSlice(), valueOffset(position) + offset, length); }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { AbstractFixedWidthBlock fixedWidthBlock = (AbstractFixedWidthBlock) block; sliceOutput.appendInt(fixedWidthBlock.getFixedSize()); sliceOutput.appendInt(fixedWidthBlock.getPositionCount()); // write null bits 8 at a time encodeNullsAsBits(sliceOutput, fixedWidthBlock); Slice slice = fixedWidthBlock.getRawSlice(); sliceOutput .appendInt(slice.length()) .writeBytes(slice); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { writeBytesTo(position, 0, getSliceLength(position), blockBuilder); blockBuilder.closeEntry(); }
@Override public long getEstimatedDataSizeForStats(int position) { return isNull(position) ? 0 : fixedSize; }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); Slice copy = Slices.copyOf(getRawSlice(), valueOffset(position), fixedSize); Slice valueIsNull = null; if (isNull(position)) { valueIsNull = Slices.wrappedBooleanArray(true); } return new FixedWidthBlock(fixedSize, 1, copy, valueIsNull); }
@Override public byte getByte(int position, int offset) { checkReadablePosition(position); return getRawSlice().getByte(valueOffset(position) + offset); }
@Override public long getRegionSizeInBytes(int positionOffset, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, positionOffset, length); return (fixedSize + Byte.BYTES) * (long) length; }
@Override public int getInt(int position, int offset) { checkReadablePosition(position); return getRawSlice().getInt(valueOffset(position) + offset); }
@Override public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length) { checkReadablePosition(position); if (fixedSize < length) { return false; } int thisOffset = valueOffset(position) + offset; return otherBlock.bytesEqual(otherPosition, otherOffset, getRawSlice(), thisOffset, length); }
@Override public short getShort(int position, int offset) { checkReadablePosition(position); return getRawSlice().getShort(valueOffset(position) + offset); }
@Override public long getLong(int position, int offset) { checkReadablePosition(position); return getRawSlice().getLong(valueOffset(position) + offset); }
@Override public Slice getSlice(int position, int offset, int length) { checkReadablePosition(position); return getRawSlice().slice(valueOffset(position) + offset, length); }
@Override public boolean bytesEqual(int position, int offset, Slice otherSlice, int otherOffset, int length) { checkReadablePosition(position); int thisOffset = valueOffset(position) + offset; return getRawSlice().equals(thisOffset, length, otherSlice, otherOffset, length); }
@Override public int bytesCompare(int position, int offset, int length, Slice otherSlice, int otherOffset, int otherLength) { checkReadablePosition(position); return getRawSlice().compareTo(valueOffset(position) + offset, length, otherSlice, otherOffset, otherLength); }
@Override public int compareTo(int position, int offset, int length, Block otherBlock, int otherPosition, int otherOffset, int otherLength) { checkReadablePosition(position); if (fixedSize < length) { throw new IllegalArgumentException("Length longer than value length"); } int thisOffset = valueOffset(position) + offset; return -otherBlock.bytesCompare(otherPosition, otherOffset, otherLength, getRawSlice(), thisOffset, length); }