Search in sources :

Example 1 with PagesIndex

use of io.trino.operator.PagesIndex in project trino by trinodb.

the class MatchAssert method identityEvaluator.

private static LabelEvaluator identityEvaluator(int[] input) {
    // create dummy WindowIndex for the LabelEvaluator
    PagesIndex pagesIndex = new PagesIndex.TestingFactory(false).newPagesIndex(ImmutableList.of(), 1);
    pagesIndex.addPage(new Page(1));
    return new IdentityEvaluator(input, new ProjectingPagesWindowIndex(pagesIndex, 0, 1, ImmutableList.of(), ImmutableList.of()));
}
Also used : ProjectingPagesWindowIndex(io.trino.operator.window.pattern.ProjectingPagesWindowIndex) Page(io.trino.spi.Page) PagesIndex(io.trino.operator.PagesIndex)

Example 2 with PagesIndex

use of io.trino.operator.PagesIndex in project trino by trinodb.

the class BenchmarkPagesSort method runPagesIndexSortBenchmark.

@Benchmark
public List<Page> runPagesIndexSortBenchmark(PagesIndexSortBenchmarkData data) {
    PagesIndex.TestingFactory pagesIndexFactory = new PagesIndex.TestingFactory(false);
    PagesIndex pageIndex = pagesIndexFactory.newPagesIndex(data.getTypes(), data.getTotalPositions());
    for (Page page : data.getPages()) {
        pageIndex.addPage(page);
    }
    pageIndex.sort(data.getSortChannels(), data.getSortOrders());
    return Streams.stream(pageIndex.getSortedPages()).collect(toImmutableList());
}
Also used : Page(io.trino.spi.Page) SequencePageBuilder.createSequencePage(io.trino.SequencePageBuilder.createSequencePage) PagesIndex(io.trino.operator.PagesIndex) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with PagesIndex

use of io.trino.operator.PagesIndex in project trino by trinodb.

the class AbstractTestAggregationFunction method testSlidingWindow.

@Test
public void testSlidingWindow() {
    // Builds trailing windows of length 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0
    int totalPositions = 12;
    int[] windowWidths = new int[totalPositions];
    Object[] expectedValues = new Object[totalPositions];
    for (int i = 0; i < totalPositions; ++i) {
        int windowWidth = Integer.min(i, totalPositions - 1 - i);
        windowWidths[i] = windowWidth;
        expectedValues[i] = getExpectedValue(i, windowWidth);
    }
    Page inputPage = new Page(totalPositions, getSequenceBlocks(0, totalPositions));
    PagesIndex pagesIndex = new PagesIndex.TestingFactory(false).newPagesIndex(getFunctionParameterTypes(), totalPositions);
    pagesIndex.addPage(inputPage);
    WindowIndex windowIndex = new PagesWindowIndex(pagesIndex, 0, totalPositions - 1);
    ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of(getFunctionName()), fromTypes(getFunctionParameterTypes()));
    AggregationMetadata aggregationMetadata = functionResolution.getPlannerContext().getFunctionManager().getAggregateFunctionImplementation(resolvedFunction);
    WindowAccumulator aggregation = createWindowAccumulator(resolvedFunction, aggregationMetadata);
    int oldStart = 0;
    int oldWidth = 0;
    for (int start = 0; start < totalPositions; ++start) {
        int width = windowWidths[start];
        // Note that add/removeInput's interval is inclusive on both ends
        if (aggregationMetadata.getRemoveInputFunction().isPresent()) {
            for (int oldi = oldStart; oldi < oldStart + oldWidth; ++oldi) {
                if (oldi < start || oldi >= start + width) {
                    aggregation.removeInput(windowIndex, oldi, oldi);
                }
            }
            for (int newi = start; newi < start + width; ++newi) {
                if (newi < oldStart || newi >= oldStart + oldWidth) {
                    aggregation.addInput(windowIndex, newi, newi);
                }
            }
        } else {
            aggregation = createWindowAccumulator(resolvedFunction, aggregationMetadata);
            aggregation.addInput(windowIndex, start, start + width - 1);
        }
        oldStart = start;
        oldWidth = width;
        Type outputType = resolvedFunction.getSignature().getReturnType();
        BlockBuilder blockBuilder = outputType.createBlockBuilder(null, 1000);
        aggregation.evaluateFinal(blockBuilder);
        Block block = blockBuilder.build();
        assertThat(makeValidityAssertion(expectedValues[start]).apply(BlockAssertions.getOnlyValue(outputType, block), expectedValues[start])).isTrue();
    }
}
Also used : ResolvedFunction(io.trino.metadata.ResolvedFunction) Page(io.trino.spi.Page) PagesIndex(io.trino.operator.PagesIndex) Type(io.trino.spi.type.Type) PagesWindowIndex(io.trino.operator.window.PagesWindowIndex) WindowIndex(io.trino.spi.function.WindowIndex) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) PagesWindowIndex(io.trino.operator.window.PagesWindowIndex) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

PagesIndex (io.trino.operator.PagesIndex)3 Page (io.trino.spi.Page)3 SequencePageBuilder.createSequencePage (io.trino.SequencePageBuilder.createSequencePage)1 ResolvedFunction (io.trino.metadata.ResolvedFunction)1 PagesWindowIndex (io.trino.operator.window.PagesWindowIndex)1 ProjectingPagesWindowIndex (io.trino.operator.window.pattern.ProjectingPagesWindowIndex)1 Block (io.trino.spi.block.Block)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)1 WindowIndex (io.trino.spi.function.WindowIndex)1 Type (io.trino.spi.type.Type)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 Test (org.testng.annotations.Test)1