@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); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new IntArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Override public Block getRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); return createArrayBlockInternal( position + getOffsetBase(), length, getValueIsNull(), getOffsets(), getRawElementBlock()); }
@Override public void appendTo(Block block, int position, BlockBuilder blockBuilder) { if (block.isNull(position)) { blockBuilder.appendNull(); } else { blockBuilder.writeLong(block.getLong(position, 0)).closeEntry(); } }
@Override public long getPositionsSizeInBytes(boolean[] positions) { checkValidPositions(positions, positionCount); boolean[] used = new boolean[dictionary.getPositionCount()]; for (int i = 0; i < positions.length; i++) { if (positions[i]) { used[getId(i)] = true; } } return dictionary.getPositionsSizeInBytes(used) + (Integer.BYTES * (long) countUsedPositions(positions)); }
@Test public void testRunLengthEncodedBlock() { BlockBuilder blockBuilder = new LongArrayBlockBuilder(null, 1); writeEntries(1, blockBuilder, BIGINT); checkRetainedSize(new RunLengthEncodedBlock(blockBuilder.build(), 1), false); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { writeBytesTo(position, 0, getSliceLength(position), blockBuilder); blockBuilder.closeEntry(); }
@Override public Block getLoadedBlock() { Block loadedDictionary = dictionary.getLoadedBlock(); if (loadedDictionary == dictionary) { return this; } return new DictionaryBlock(idsOffset, getPositionCount(), loadedDictionary, ids, false, randomDictionaryId()); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); for (int i = offset; i < offset + length; i++) { checkValidPosition(positions[i], positionCount); } return new RunLengthEncodedBlock(value.copyRegion(0, 1), length); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new ByteArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Override public Block getRegion(int positionOffset, int length) { checkValidRegion(getPositionCount(), positionOffset, length); if (!hasNonNullValue) { return new RunLengthEncodedBlock(NULL_VALUE_BLOCK, length); } return new ShortArrayBlock(positionOffset, length, hasNullValue ? valueIsNull : null, values); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(positionCount, positionOffset, length); return new RunLengthEncodedBlock(value.copyRegion(0, 1), length); }
@Override public BlockBuilder newBlockBuilderLike(BlockBuilderStatus blockBuilderStatus) { int newSize = calculateBlockResetSize(getPositionCount()); BlockBuilder[] newBlockBuilders = new BlockBuilder[numFields]; for (int i = 0; i < numFields; i++) { newBlockBuilders[i] = fieldBlockBuilders[i].newBlockBuilderLike(blockBuilderStatus); } return new RowBlockBuilder(blockBuilderStatus, newBlockBuilders, new int[newSize + 1], new boolean[newSize]); } }
/** * Create a new block from the current block by keeping the same elements * only with respect to {@code positions} that starts at {@code offset} and has length of {@code length}. * May return a view over the data in this block or may return a copy */ default Block getPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); return new DictionaryBlock(offset, length, this, positions, false, randomDictionaryId()); }
@Override public BlockBuilder newBlockBuilderLike(BlockBuilderStatus blockBuilderStatus) { int newSize = calculateBlockResetSize(getPositionCount()); return new ArrayBlockBuilder(blockBuilderStatus, values.newBlockBuilderLike(blockBuilderStatus), newSize); }
@Override public long getRegionSizeInBytes(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int valueStart = getOffsets()[getOffsetBase() + position]; int valueEnd = getOffsets()[getOffsetBase() + position + length]; return getRawElementBlock().getRegionSizeInBytes(valueStart, valueEnd - valueStart) + ((Integer.BYTES + Byte.BYTES) * (long) length); }
@Override public Block getRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); return createRowBlockInternal(position + getOffsetBase(), length, getRowIsNull(), getFieldBlockOffsets(), getRawFieldBlocks()); }
@Override public short getShort(int position, int offset) { checkReadablePosition(position); return getBlock().getShort(position + start, offset); }