Search in sources :

Example 51 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class MultiChannelGroupByHash method startNewPage.

private void startNewPage() {
    if (currentPageBuilder != null) {
        completedPagesMemorySize += currentPageBuilder.getRetainedSizeInBytes();
        currentPageBuilder = currentPageBuilder.newPageBuilderLike();
    } else {
        currentPageBuilder = new PageBuilder(types);
    }
    for (int i = 0; i < types.size(); i++) {
        channelBuilders.get(i).add(currentPageBuilder.getBlockBuilder(i));
    }
}
Also used : PageBuilder(io.prestosql.spi.PageBuilder)

Example 52 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class TestPagesIndexPageSorter method createOutputPages.

private static List<Page> createOutputPages(List<Type> types, List<Page> inputPages, long[] sortedAddresses) {
    PageBuilder pageBuilder = new PageBuilder(types);
    pageBuilder.reset();
    for (long address : sortedAddresses) {
        int index = sorter.decodePageIndex(address);
        int position = sorter.decodePositionIndex(address);
        Page page = inputPages.get(index);
        for (int i = 0; i < types.size(); i++) {
            Type type = types.get(i);
            type.appendTo(page.getBlock(i), position, pageBuilder.getBlockBuilder(i));
        }
        pageBuilder.declarePosition();
    }
    return ImmutableList.of(pageBuilder.build());
}
Also used : Type(io.prestosql.spi.type.Type) Page(io.prestosql.spi.Page) PageBuilder(io.prestosql.spi.PageBuilder)

Example 53 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class TestBlockBuilder method testNewBlockBuilderLike.

@Test
public void testNewBlockBuilderLike() {
    ArrayType longArrayType = new ArrayType(BIGINT);
    ArrayType arrayType = new ArrayType(longArrayType);
    List<Type> channels = ImmutableList.of(BIGINT, VARCHAR, arrayType);
    PageBuilder pageBuilder = new PageBuilder(channels);
    BlockBuilder bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
    BlockBuilder arrayBlockBuilder = pageBuilder.getBlockBuilder(2);
    for (int i = 0; i < 100; i++) {
        BIGINT.writeLong(bigintBlockBuilder, i);
        VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
        Block longArrayBlock = new ArrayType(BIGINT).createBlockBuilder(null, 1).appendStructure(BIGINT.createBlockBuilder(null, 2).writeLong(i).closeEntry().writeLong(i * 2).closeEntry().build());
        arrayBlockBuilder.appendStructure(longArrayBlock);
        pageBuilder.declarePosition();
    }
    PageBuilder newPageBuilder = pageBuilder.newPageBuilderLike();
    for (int i = 0; i < channels.size(); i++) {
        assertEquals(newPageBuilder.getType(i), pageBuilder.getType(i));
        // we should get new block builder instances
        assertNotEquals(pageBuilder.getBlockBuilder(i), newPageBuilder.getBlockBuilder(i));
        assertEquals(newPageBuilder.getBlockBuilder(i).getPositionCount(), 0);
        assertTrue(newPageBuilder.getBlockBuilder(i).getRetainedSizeInBytes() < pageBuilder.getBlockBuilder(i).getRetainedSizeInBytes());
    }
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) ArrayType(io.prestosql.spi.type.ArrayType) Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) PageBuilder(io.prestosql.spi.PageBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 54 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class TestBlockBuilder method testPageBuilderBlockBuilderSnapshot.

@Test
public void testPageBuilderBlockBuilderSnapshot() {
    PagesSerde serde = TestingPagesSerdeFactory.testingPagesSerde();
    List<Type> channels = ImmutableList.of(BIGINT, VARCHAR, INTEGER);
    PageBuilder pageBuilder = new PageBuilder(channels);
    BlockBuilder bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
    BlockBuilder intBlockBuilder = pageBuilder.getBlockBuilder(2);
    for (int i = 0; i < 100; i++) {
        BIGINT.writeLong(bigintBlockBuilder, i);
        VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
        INTEGER.writeLong(intBlockBuilder, i);
        pageBuilder.declarePosition();
    }
    Page withoutRestore = pageBuilder.build();
    pageBuilder.reset();
    bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
    varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
    intBlockBuilder = pageBuilder.getBlockBuilder(2);
    for (int i = 0; i < 50; i++) {
        BIGINT.writeLong(bigintBlockBuilder, i);
        VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
        INTEGER.writeLong(intBlockBuilder, i);
        pageBuilder.declarePosition();
    }
    Object snapshot = pageBuilder.capture(serde);
    for (int i = 50; i < 90; i++) {
        BIGINT.writeLong(bigintBlockBuilder, i);
        VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
        INTEGER.writeLong(intBlockBuilder, i);
        pageBuilder.declarePosition();
    }
    pageBuilder.restore(snapshot, serde);
    for (int i = 50; i < 100; i++) {
        BIGINT.writeLong(bigintBlockBuilder, i);
        VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
        INTEGER.writeLong(intBlockBuilder, i);
        pageBuilder.declarePosition();
    }
    Page withRestore = pageBuilder.build();
    assertPageEquals(channels, withRestore, withoutRestore);
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Type(io.prestosql.spi.type.Type) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Page(io.prestosql.spi.Page) PageBuilder(io.prestosql.spi.PageBuilder) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 55 with PageBuilder

use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.

the class TestGroupByHash method testAppendToMultipleTuplesPerGroup.

@Test
public void testAppendToMultipleTuplesPerGroup() {
    List<Long> values = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        values.add(i % 50);
    }
    Block valuesBlock = BlockAssertions.createLongsBlock(values);
    Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    assertEquals(groupByHash.getGroupCount(), 50);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page outputPage = pageBuilder.build();
    assertEquals(outputPage.getPositionCount(), 50);
    BlockAssertions.assertBlockEquals(BIGINT, outputPage.getBlock(0), BlockAssertions.createLongSequenceBlock(0, 50));
}
Also used : ArrayList(java.util.ArrayList) GroupByHash.createGroupByHash(io.prestosql.operator.GroupByHash.createGroupByHash) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) TypeUtils.getHashBlock(io.prestosql.type.TypeUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringSequenceBlock(io.prestosql.block.BlockAssertions.createStringSequenceBlock) Page(io.prestosql.spi.Page) PageBuilder(io.prestosql.spi.PageBuilder) Test(org.testng.annotations.Test)

Aggregations

PageBuilder (io.prestosql.spi.PageBuilder)58 Page (io.prestosql.spi.Page)28 BlockBuilder (io.prestosql.spi.block.BlockBuilder)27 Type (io.prestosql.spi.type.Type)24 ImmutableList (com.google.common.collect.ImmutableList)18 Test (org.testng.annotations.Test)14 List (java.util.List)11 Block (io.prestosql.spi.block.Block)10 ArrayList (java.util.ArrayList)9 INTEGER (io.prestosql.spi.type.IntegerType.INTEGER)8 Collectors.toList (java.util.stream.Collectors.toList)8 Slice (io.airlift.slice.Slice)7 Benchmark (org.openjdk.jmh.annotations.Benchmark)7 Slices (io.airlift.slice.Slices)6 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)6 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)6 ArrayType (io.prestosql.spi.type.ArrayType)6 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)6 DOUBLE (io.prestosql.spi.type.DoubleType.DOUBLE)6 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)6