Search in sources :

Example 16 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class MergeSortedPages method buildPage.

private static WorkProcessor<Page> buildPage(WorkProcessor<PageWithPosition> pageWithPositions, List<Integer> outputChannels, List<Type> outputTypes, BiPredicate<PageBuilder, PageWithPosition> pageBreakPredicate, boolean updateMemoryAfterEveryPosition, AggregatedMemoryContext aggregatedMemoryContext, DriverYieldSignal yieldSignal) {
    LocalMemoryContext memoryContext = aggregatedMemoryContext.newLocalMemoryContext(MergeSortedPages.class.getSimpleName());
    PageBuilder pageBuilder = new PageBuilder(outputTypes);
    return pageWithPositions.yielding(yieldSignal::isSet).transform(pageWithPosition -> {
        boolean finished = pageWithPosition == null;
        if (finished && pageBuilder.isEmpty()) {
            memoryContext.close();
            return TransformationState.finished();
        }
        if (finished || pageBreakPredicate.test(pageBuilder, pageWithPosition)) {
            if (!updateMemoryAfterEveryPosition) {
                // update memory usage just before producing page to cap from top
                memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
            }
            Page page = pageBuilder.build();
            pageBuilder.reset();
            if (!finished) {
                pageWithPosition.appendTo(pageBuilder, outputChannels, outputTypes);
            }
            if (updateMemoryAfterEveryPosition) {
                memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
            }
            return TransformationState.ofResult(page, !finished);
        }
        pageWithPosition.appendTo(pageBuilder, outputChannels, outputTypes);
        if (updateMemoryAfterEveryPosition) {
            memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
        }
        return TransformationState.needsMoreData();
    });
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder)

Example 17 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkGroupByHash method createVarcharPages.

private static List<Page> createVarcharPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled) {
    List<Type> types = Collections.nCopies(channelCount, VARCHAR);
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    if (hashEnabled) {
        types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
    }
    PageBuilder pageBuilder = new PageBuilder(types);
    for (int position = 0; position < positionCount; position++) {
        int rand = ThreadLocalRandom.current().nextInt(groupCount);
        Slice value = Slices.wrappedBuffer(ByteBuffer.allocate(4).putInt(rand).flip());
        pageBuilder.declarePosition();
        for (int channel = 0; channel < channelCount; channel++) {
            VARCHAR.writeSlice(pageBuilder.getBlockBuilder(channel), value);
        }
        if (hashEnabled) {
            BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), XxHash64.hash(value));
        }
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pages.build();
}
Also used : Type(io.trino.spi.type.Type) AbstractLongType(io.trino.spi.type.AbstractLongType) ImmutableList(com.google.common.collect.ImmutableList) Slice(io.airlift.slice.Slice) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder)

Example 18 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkGroupByHash method addPagePreCompute.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object addPagePreCompute(BenchmarkData data) {
    GroupByHash groupByHash = new MultiChannelGroupByHash(data.getTypes(), data.getChannels(), data.getHashChannel(), EXPECTED_SIZE, false, getJoinCompiler(), TYPE_OPERATOR_FACTORY, NOOP);
    addInputPagesToHash(groupByHash, data.getPages());
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(groupId, pageBuilder, 0);
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pageBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Example 19 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkGroupedTopNRankBuilder method createInputPage.

private static Page createInputPage(int positions, List<Type> types) {
    PageBuilder pageBuilder = new PageBuilder(types);
    LineItemGenerator lineItemGenerator = new LineItemGenerator(1, 1, 1);
    Iterator<LineItem> iterator = lineItemGenerator.iterator();
    for (int i = 0; i < positions; i++) {
        pageBuilder.declarePosition();
        LineItem lineItem = iterator.next();
        DOUBLE.writeDouble(pageBuilder.getBlockBuilder(EXTENDED_PRICE), lineItem.getExtendedPrice());
        DOUBLE.writeDouble(pageBuilder.getBlockBuilder(DISCOUNT), lineItem.getDiscount());
        VARCHAR.writeString(pageBuilder.getBlockBuilder(STATUS), lineItem.getStatus());
        BIGINT.writeLong(pageBuilder.getBlockBuilder(QUANTITY), lineItem.getQuantity());
    }
    return pageBuilder.build();
}
Also used : LineItem(io.trino.tpch.LineItem) PageBuilder(io.trino.spi.PageBuilder) LineItemGenerator(io.trino.tpch.LineItemGenerator)

Example 20 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkGroupedTopNRowNumberBuilder method createInputPage.

private static Page createInputPage(int positions, List<Type> types) {
    PageBuilder pageBuilder = new PageBuilder(types);
    LineItemGenerator lineItemGenerator = new LineItemGenerator(1, 1, 1);
    Iterator<LineItem> iterator = lineItemGenerator.iterator();
    for (int i = 0; i < positions; i++) {
        pageBuilder.declarePosition();
        LineItem lineItem = iterator.next();
        DOUBLE.writeDouble(pageBuilder.getBlockBuilder(EXTENDED_PRICE), lineItem.getExtendedPrice());
        DOUBLE.writeDouble(pageBuilder.getBlockBuilder(DISCOUNT), lineItem.getDiscount());
        DATE.writeLong(pageBuilder.getBlockBuilder(SHIP_DATE), lineItem.getShipDate());
        DOUBLE.writeDouble(pageBuilder.getBlockBuilder(QUANTITY), lineItem.getQuantity());
    }
    return pageBuilder.build();
}
Also used : LineItem(io.trino.tpch.LineItem) PageBuilder(io.trino.spi.PageBuilder) LineItemGenerator(io.trino.tpch.LineItemGenerator)

Aggregations

PageBuilder (io.trino.spi.PageBuilder)58 BlockBuilder (io.trino.spi.block.BlockBuilder)24 Page (io.trino.spi.Page)23 Type (io.trino.spi.type.Type)22 ImmutableList (com.google.common.collect.ImmutableList)14 Block (io.trino.spi.block.Block)11 Test (org.testng.annotations.Test)10 List (java.util.List)8 Slice (io.airlift.slice.Slice)6 ArrayType (io.trino.spi.type.ArrayType)6 INTEGER (io.trino.spi.type.IntegerType.INTEGER)5 Slices (io.airlift.slice.Slices)4 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)4 DictionaryBlock (io.trino.spi.block.DictionaryBlock)4 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)4 BIGINT (io.trino.spi.type.BigintType.BIGINT)4 DOUBLE (io.trino.spi.type.DoubleType.DOUBLE)4 MapType (io.trino.spi.type.MapType)4 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)4 RowType (io.trino.spi.type.RowType)3