Java Code Examples for io.prestosql.spi.block.Block#copyRegion()

The following examples show how to use io.prestosql.spi.block.Block#copyRegion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagesIndex.java    From presto with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: PagesIndex.java    From presto with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: Page.java    From presto with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: TestVariableWidthBlock.java    From presto with Apache License 2.0 5 votes vote down vote up
@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());
}