@Override public Block copyRegion(int positionOffset, int length) { return block.copyRegion(positionOffset, length); }
@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); }
protected static void assertNotCompact(Block block) { assertNotSame(block.copyRegion(0, block.getPositionCount()), block); }
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 assertCompact(Block block) { assertSame(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)); } }
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(); }
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()); }
@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()); }
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); }