@Override public long getEstimatedDataSizeForStats(int position) { return isNull(position) ? 0 : getSliceLength(position); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { writeBytesTo(position, 0, getSliceLength(position), blockBuilder); blockBuilder.closeEntry(); }
@Override public int compareTo(int position, int offset, int length, Block otherBlock, int otherPosition, int otherOffset, int otherLength) { checkReadablePosition(position); Slice rawSlice = getRawSlice(position); if (getSliceLength(position) < length) { throw new IllegalArgumentException("Length longer than value length"); } return -otherBlock.bytesCompare(otherPosition, otherOffset, otherLength, rawSlice, getPositionOffset(position) + offset, length); }
@Override public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length) { checkReadablePosition(position); Slice rawSlice = getRawSlice(position); if (getSliceLength(position) < length) { return false; } return otherBlock.bytesEqual(otherPosition, otherOffset, rawSlice, getPositionOffset(position) + offset, length); }
@Override public Block getSingleValueBlock(int position) { if (isNull(position)) { return new VariableWidthBlock(0, 1, EMPTY_SLICE, new int[] {0, 0}, new boolean[] {true}); } int offset = getPositionOffset(position); int entrySize = getSliceLength(position); Slice copy = Slices.copyOf(getRawSlice(position), offset, entrySize); return new VariableWidthBlock(0, 1, copy, new int[] {0, copy.length()}, null); }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { // The down casts here are safe because it is the block itself the provides this encoding implementation. AbstractVariableWidthBlock variableWidthBlock = (AbstractVariableWidthBlock) block; int positionCount = variableWidthBlock.getPositionCount(); sliceOutput.appendInt(positionCount); // offsets int totalLength = 0; for (int position = 0; position < positionCount; position++) { int length = variableWidthBlock.getSliceLength(position); totalLength += length; sliceOutput.appendInt(totalLength); } encodeNullsAsBits(sliceOutput, variableWidthBlock); sliceOutput .appendInt(totalLength) .writeBytes(variableWidthBlock.getRawSlice(0), variableWidthBlock.getPositionOffset(0), totalLength); }
@Override public long getEstimatedDataSizeForStats(int position) { return isNull(position) ? 0 : getSliceLength(position); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { writeBytesTo(position, 0, getSliceLength(position), blockBuilder); blockBuilder.closeEntry(); }
@Override public int compareTo(int position, int offset, int length, Block otherBlock, int otherPosition, int otherOffset, int otherLength) { checkReadablePosition(position); Slice rawSlice = getRawSlice(position); if (getSliceLength(position) < length) { throw new IllegalArgumentException("Length longer than value length"); } return -otherBlock.bytesCompare(otherPosition, otherOffset, otherLength, rawSlice, getPositionOffset(position) + offset, length); }
@Override public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length) { checkReadablePosition(position); Slice rawSlice = getRawSlice(position); if (getSliceLength(position) < length) { return false; } return otherBlock.bytesEqual(otherPosition, otherOffset, rawSlice, getPositionOffset(position) + offset, length); }
@Override public Block getSingleValueBlock(int position) { if (isNull(position)) { return new VariableWidthBlock(0, 1, EMPTY_SLICE, new int[] {0, 0}, new boolean[] {true}); } int offset = getPositionOffset(position); int entrySize = getSliceLength(position); Slice copy = Slices.copyOf(getRawSlice(position), offset, entrySize); return new VariableWidthBlock(0, 1, copy, new int[] {0, copy.length()}, null); }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { // The down casts here are safe because it is the block itself the provides this encoding implementation. AbstractVariableWidthBlock variableWidthBlock = (AbstractVariableWidthBlock) block; int positionCount = variableWidthBlock.getPositionCount(); sliceOutput.appendInt(positionCount); // offsets int totalLength = 0; for (int position = 0; position < positionCount; position++) { int length = variableWidthBlock.getSliceLength(position); totalLength += length; sliceOutput.appendInt(totalLength); } encodeNullsAsBits(sliceOutput, variableWidthBlock); sliceOutput .appendInt(totalLength) .writeBytes(variableWidthBlock.getRawSlice(0), variableWidthBlock.getPositionOffset(0), totalLength); }