Search in sources :

Example 21 with PageProcessor

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

the class TestFilterAndProjectOperator method test.

@Test
public void test() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).build();
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    RowExpression filter = call(functionResolution.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(BIGINT, BIGINT)), field(1, BIGINT), constant(9L, BIGINT));
    RowExpression field0 = field(0, VARCHAR);
    RowExpression add5 = call(functionResolution.resolveOperator(ADD, ImmutableList.of(BIGINT, BIGINT)), field(1, BIGINT), constant(5L, BIGINT));
    ExpressionCompiler compiler = functionResolution.getExpressionCompiler();
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field0, add5));
    OperatorFactory operatorFactory = FilterAndProjectOperator.createOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(VARCHAR, BIGINT), DataSize.ofBytes(0), 0);
    MaterializedResult expected = MaterializedResult.resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("0", 5L).row("1", 6L).row("2", 7L).row("3", 8L).row("4", 9L).row("5", 10L).row("6", 11L).row("7", 12L).row("8", 13L).row("9", 14L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProcessor(io.trino.operator.project.PageProcessor) RowExpression(io.trino.sql.relational.RowExpression) Page(io.trino.spi.Page) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 22 with PageProcessor

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

the class AbstractOperatorBenchmark method createHashProjectOperator.

protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) {
    SymbolAllocator symbolAllocator = new SymbolAllocator();
    ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder();
    ImmutableList.Builder<PageProjection> projections = ImmutableList.builder();
    for (int channel = 0; channel < types.size(); channel++) {
        Symbol symbol = symbolAllocator.newSymbol("h" + channel, types.get(channel));
        symbolToInputMapping.put(symbol, channel);
        projections.add(new InputPageProjection(channel, types.get(channel)));
    }
    Map<Symbol, Type> symbolTypes = symbolAllocator.getTypes().allTypes();
    Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(session, localQueryRunner.getMetadata(), symbolAllocator, ImmutableList.copyOf(symbolTypes.keySet()));
    verify(hashExpression.isPresent());
    Map<NodeRef<Expression>, Type> expressionTypes = createTestingTypeAnalyzer(localQueryRunner.getPlannerContext()).getTypes(session, TypeProvider.copyOf(symbolTypes), hashExpression.get());
    RowExpression translated = translate(hashExpression.get(), expressionTypes, symbolToInputMapping.buildOrThrow(), localQueryRunner.getMetadata(), localQueryRunner.getFunctionManager(), session, false);
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0);
    projections.add(functionCompiler.compileProjection(translated, Optional.empty()).get());
    return FilterAndProjectOperator.createOperatorFactory(operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session));
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) Symbol(io.trino.sql.planner.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowExpression(io.trino.sql.relational.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) PageProjection(io.trino.operator.project.PageProjection) InputPageProjection(io.trino.operator.project.InputPageProjection) NodeRef(io.trino.sql.tree.NodeRef) Type(io.trino.spi.type.Type) InputPageProjection(io.trino.operator.project.InputPageProjection) PageProcessor(io.trino.operator.project.PageProcessor) Expression(io.trino.sql.tree.Expression) RowExpression(io.trino.sql.relational.RowExpression)

Example 23 with PageProcessor

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

the class PredicateFilterBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
    RowExpression filter = call(localQueryRunner.getMetadata().resolveOperator(session, LESS_THAN_OR_EQUAL, ImmutableList.of(DOUBLE, DOUBLE)), constant(50000.0, DOUBLE), field(0, DOUBLE));
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(localQueryRunner.getFunctionManager(), new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0));
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, DOUBLE)));
    OperatorFactory filterAndProjectOperator = FilterAndProjectOperator.createOperatorFactory(1, new PlanNodeId("test"), pageProcessor, ImmutableList.of(DOUBLE), DataSize.ofBytes(0), 0);
    return ImmutableList.of(tableScanOperator, filterAndProjectOperator);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) PageProcessor(io.trino.operator.project.PageProcessor) OperatorFactory(io.trino.operator.OperatorFactory) RowExpression(io.trino.sql.relational.RowExpression) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler)

Aggregations

PageProcessor (io.trino.operator.project.PageProcessor)23 Page (io.trino.spi.Page)17 Test (org.testng.annotations.Test)17 RowExpression (io.trino.sql.relational.RowExpression)13 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)12 CursorProcessor (io.trino.operator.project.CursorProcessor)8 DriverYieldSignal (io.trino.operator.DriverYieldSignal)7 CatalogName (io.trino.connector.CatalogName)6 Split (io.trino.metadata.Split)6 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)6 TestingSplit (io.trino.testing.TestingSplit)6 ExpressionCompiler (io.trino.sql.gen.ExpressionCompiler)5 MaterializedResult (io.trino.testing.MaterializedResult)5 ImmutableList (com.google.common.collect.ImmutableList)4 FunctionManager (io.trino.metadata.FunctionManager)4 ResolvedFunction (io.trino.metadata.ResolvedFunction)4 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)4 CallExpression (io.trino.sql.relational.CallExpression)4 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)3 PageRecordSet (io.trino.operator.index.PageRecordSet)3