@Override public Block copyRegion(int positionOffset, int length) { return block.copyRegion(positionOffset, length); }
@Override public Block copyRegion(int position, int length) { assureLoaded(); return block.copyRegion(position, length); }
@Override public Block copyRegion(int positionOffset, int length) { checkValidRegion(positionCount, positionOffset, length); return new RunLengthEncodedBlock(value.copyRegion(0, 1), length); }
@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 getSingleValueBlock(int position) { checkReadablePosition(position); int startValueOffset = getOffset(position); int endValueOffset = getOffset(position + 1); int valueLength = endValueOffset - startValueOffset; Block newKeys = getRawKeyBlock().copyRegion(startValueOffset, valueLength); Block newValues = getRawValueBlock().copyRegion(startValueOffset, valueLength); int[] newHashTable = Arrays.copyOfRange(getHashTables(), startValueOffset * HASH_MULTIPLIER, endValueOffset * HASH_MULTIPLIER); return createMapBlockInternal( 0, 1, Optional.of(new boolean[] {isNull(position)}), new int[] {0, valueLength}, newKeys, newValues, newHashTable, keyType, keyBlockNativeEquals, keyNativeHashCode); }
public void compact() { if (getRetainedSizeInBytes() <= getSizeInBytes()) { return; } for (int i = 0; i < blocks.length; i++) { Block block = blocks[i]; if (block instanceof DictionaryBlock) { continue; } // Compact the block blocks[i] = block.copyRegion(0, block.getPositionCount()); } Map<DictionaryId, DictionaryBlockIndexes> dictionaryBlocks = getRelatedDictionaryBlocks(); for (DictionaryBlockIndexes blockIndexes : dictionaryBlocks.values()) { List<DictionaryBlock> compactBlocks = compactRelatedBlocks(blockIndexes.getBlocks()); List<Integer> indexes = blockIndexes.getIndexes(); for (int i = 0; i < compactBlocks.size(); i++) { blocks[indexes.get(i)] = compactBlocks.get(i); } } updateRetainedSize(); }
protected static void assertCompact(Block block) { assertSame(block.copyRegion(0, block.getPositionCount()), block); }
protected static void assertNotCompact(Block block) { assertNotSame(block.copyRegion(0, block.getPositionCount()), block); }
protected static void testCopyRegionCompactness(Block block) { assertCompact(block.copyRegion(0, block.getPositionCount())); if (block.getPositionCount() > 0) { assertCompact(block.copyRegion(0, block.getPositionCount() - 1)); assertCompact(block.copyRegion(1, block.getPositionCount() - 1)); } }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); int startValueOffset = getOffset(position); int valueLength = getOffset(position + 1) - startValueOffset; Block newValues = getRawElementBlock().copyRegion(startValueOffset, valueLength); return createArrayBlockInternal( 0, 1, new boolean[] {isNull(position)}, new int[] {0, valueLength}, newValues); }
@Override public Block getSingleValueBlock(int position) { checkReadablePosition(position); int startFieldBlockOffset = getFieldBlockOffset(position); int endFieldBlockOffset = getFieldBlockOffset(position + 1); int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset; Block[] newBlocks = new Block[numFields]; for (int i = 0; i < numFields; i++) { newBlocks[i] = getRawFieldBlocks()[i].copyRegion(startFieldBlockOffset, fieldBlockLength); } boolean[] newRowIsNull = new boolean[] {isNull(position)}; int[] newOffsets = new int[] {0, fieldBlockLength}; return createRowBlockInternal(0, 1, newRowIsNull, newOffsets, newBlocks); }
public void compact() { if (eagerCompact) { return; } for (int channel = 0; channel < types.size(); channel++) { ObjectArrayList<Block> blocks = channels[channel]; for (int i = nextBlockToCompact; i < blocks.size(); i++) { Block block = blocks.get(i); // Copy the block to compact its size Block compactedBlock = block.copyRegion(0, block.getPositionCount()); blocks.set(i, compactedBlock); pagesMemorySize -= block.getRetainedSizeInBytes(); pagesMemorySize += compactedBlock.getRetainedSizeInBytes(); } } nextBlockToCompact = channels[0].size(); estimatedSize = calculateEstimatedSize(); }
@Test public void testCopyRegion() { Slice[] expectedValues = createExpectedValues(100); Block block = createBlockBuilderWithValues(expectedValues).build(); Block actual = block.copyRegion(10, 10); Block expected = createBlockBuilderWithValues(copyOfRange(expectedValues, 10, 20)).build(); assertEquals(actual.getPositionCount(), expected.getPositionCount()); assertEquals(actual.getSizeInBytes(), expected.getSizeInBytes()); }
@Override public Block copyRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startValueOffset = getOffset(position); int endValueOffset = getOffset(position + length); Block newKeys = getRawKeyBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); Block newValues = getRawValueBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length); boolean[] mapIsNull = getMapIsNull(); boolean[] newMapIsNull = mapIsNull == null ? null : compactArray(mapIsNull, position + getOffsetBase(), length); int[] newHashTable = compactArray(getHashTables(), startValueOffset * HASH_MULTIPLIER, (endValueOffset - startValueOffset) * HASH_MULTIPLIER); if (newKeys == getRawKeyBlock() && newValues == getRawValueBlock() && newOffsets == getOffsets() && newMapIsNull == mapIsNull && newHashTable == getHashTables()) { return this; } return createMapBlockInternal( 0, length, Optional.ofNullable(newMapIsNull), newOffsets, newKeys, newValues, newHashTable, keyType, keyBlockNativeEquals, keyNativeHashCode); }
public void addPage(Page page) { // ignore empty pages if (page.getPositionCount() == 0) { return; } positionCount += page.getPositionCount(); int pageIndex = (channels.length > 0) ? channels[0].size() : 0; for (int i = 0; i < channels.length; i++) { Block block = page.getBlock(i); if (eagerCompact) { block = block.copyRegion(0, block.getPositionCount()); } channels[i].add(block); pagesMemorySize += block.getRetainedSizeInBytes(); } for (int position = 0; position < page.getPositionCount(); position++) { long sliceAddress = encodeSyntheticAddress(pageIndex, position); valueAddresses.add(sliceAddress); } estimatedSize = calculateEstimatedSize(); }
@Override public Block copyRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startValueOffset = getOffset(position); int endValueOffset = getOffset(position + length); Block newValues = getRawElementBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset); int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length); boolean[] valueIsNull = getValueIsNull(); boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, position + getOffsetBase(), length); if (newValues == getRawElementBlock() && newOffsets == getOffsets() && newValueIsNull == valueIsNull) { return this; } return createArrayBlockInternal(0, length, newValueIsNull, newOffsets, newValues); }
@Override public Block copyRegion(int position, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, position, length); int startFieldBlockOffset = getFieldBlockOffset(position); int endFieldBlockOffset = getFieldBlockOffset(position + length); int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset; Block[] newBlocks = new Block[numFields]; for (int i = 0; i < numFields; i++) { newBlocks[i] = getRawFieldBlocks()[i].copyRegion(startFieldBlockOffset, fieldBlockLength); } int[] newOffsets = compactOffsets(getFieldBlockOffsets(), position + getOffsetBase(), length); boolean[] rowIsNull = getRowIsNull(); boolean[] newRowIsNull = rowIsNull == null ? null : compactArray(rowIsNull, position + getOffsetBase(), length); if (arraySame(newBlocks, getRawFieldBlocks()) && newOffsets == getFieldBlockOffsets() && newRowIsNull == rowIsNull) { return this; } return createRowBlockInternal(0, length, newRowIsNull, newOffsets, newBlocks); }
protected <T> void assertBlockPosition(Block block, Supplier<BlockBuilder> newBlockBuilder, int position, T expectedValue, Class<?> expectedValueType) { assertPositionValue(block, position, expectedValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedValue); assertPositionValue(block.getRegion(position, 1), 0, expectedValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(position, 1)), 0, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(0, position + 1)), position, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(position, block.getPositionCount() - position)), 0, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(position, 1), newBlockBuilder), 0, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue); if (expectedValueType.isArray() || expectedValueType == List.class || expectedValueType == Map.class) { assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, 1), newBlockBuilder), 0, expectedValue); assertPositionValue(copyBlockViaWriteStructure(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue); assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue); } assertPositionValue(block.copyRegion(position, 1), 0, expectedValue); assertPositionValue(block.copyRegion(0, position + 1), position, expectedValue); assertPositionValue(block.copyRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(block.copyPositions(new int[] {position}, 0, 1), 0, expectedValue); }
private static Slice blockToSlice(Block block) { // This function is strictly for testing use only SliceOutput sliceOutput = new DynamicSliceOutput(1000); BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount())); return sliceOutput.slice(); }
private static Slice blockToSlice(Block block) { // This function is strictly for testing use only SliceOutput sliceOutput = new DynamicSliceOutput(1000); BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount())); return sliceOutput.slice(); }