Search in sources :

Example 16 with PlanVariableAllocator

use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.

the class TestPlanRemoteProjections method testLocalOnly.

@Test
void testLocalOnly() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    planBuilder.variable("x", INTEGER);
    planBuilder.variable("y", INTEGER);
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("abs(x) + abs(y)")).put(planBuilder.variable("b", BOOLEAN), planBuilder.rowExpression("x is null and y is null")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 1);
    assertEquals(rewritten.get(0).getProjections().size(), 2);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 17 with PlanVariableAllocator

use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.

the class TestPlanRemoteProjections method testRemoteAndLocal.

@Test
void testRemoteAndLocal() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    planBuilder.variable("x", INTEGER);
    planBuilder.variable("y", INTEGER);
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo(x, y + unittest.memory.remote_foo(x))")).put(planBuilder.variable("b"), planBuilder.rowExpression("abs(x)")).put(planBuilder.variable("c"), planBuilder.rowExpression("abs(unittest.memory.remote_foo())")).put(planBuilder.variable("d"), planBuilder.rowExpression("unittest.memory.remote_foo(x + y, abs(x))")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 4);
    assertEquals(rewritten.get(3).getProjections().size(), 4);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 18 with PlanVariableAllocator

use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.

the class TestJoinEnumerator method createContext.

private Rule.Context createContext() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
    CachingStatsProvider statsProvider = new CachingStatsProvider(queryRunner.getStatsCalculator(), Optional.empty(), noLookup(), queryRunner.getDefaultSession(), variableAllocator.getTypes());
    CachingCostProvider costProvider = new CachingCostProvider(queryRunner.getCostCalculator(), statsProvider, Optional.empty(), queryRunner.getDefaultSession());
    return new Rule.Context() {

        @Override
        public Lookup getLookup() {
            return noLookup();
        }

        @Override
        public PlanNodeIdAllocator getIdAllocator() {
            return planNodeIdAllocator;
        }

        @Override
        public PlanVariableAllocator getVariableAllocator() {
            return variableAllocator;
        }

        @Override
        public Session getSession() {
            return queryRunner.getDefaultSession();
        }

        @Override
        public StatsProvider getStatsProvider() {
            return statsProvider;
        }

        @Override
        public CostProvider getCostProvider() {
            return costProvider;
        }

        @Override
        public void checkTimeoutNotExhausted() {
        }

        @Override
        public WarningCollector getWarningCollector() {
            return WarningCollector.NOOP;
        }
    };
}
Also used : CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator)

Example 19 with PlanVariableAllocator

use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.

the class TestDruidPlanOptimizer method getOptimizedPlan.

private PlanNode getOptimizedPlan(PlanBuilder planBuilder, PlanNode originalPlan) {
    DruidQueryGenerator druidQueryGenerator = new DruidQueryGenerator(functionAndTypeManager, functionAndTypeManager, standardFunctionResolution);
    DruidPlanOptimizer optimizer = new DruidPlanOptimizer(druidQueryGenerator, functionAndTypeManager, new RowExpressionDeterminismEvaluator(functionAndTypeManager), functionAndTypeManager, standardFunctionResolution);
    return optimizer.optimize(originalPlan, defaultSessionHolder.getConnectorSession(), new PlanVariableAllocator(), planBuilder.getIdAllocator());
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator)

Example 20 with PlanVariableAllocator

use of com.facebook.presto.sql.planner.PlanVariableAllocator in project presto by prestodb.

the class OptimizerAssert method matches.

public void matches(PlanMatchPattern pattern) {
    PlanNode actual = optimizer.optimize(plan, session, types, new PlanVariableAllocator(), idAllocator, WarningCollector.NOOP);
    if (!ImmutableSet.copyOf(plan.getOutputVariables()).equals(ImmutableSet.copyOf(actual.getOutputVariables()))) {
        fail(String.format("%s: output schema of transformed and original plans are not equivalent\n" + "\texpected: %s\n" + "\tactual:   %s", optimizer.getClass().getName(), plan.getOutputVariables(), actual.getOutputVariables()));
    }
    inTransaction(session -> {
        assertPlan(session, metadata, statsCalculator, new Plan(actual, types, StatsAndCosts.empty()), pattern);
        return null;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanAssert.assertPlan(com.facebook.presto.sql.planner.assertions.PlanAssert.assertPlan) Plan(com.facebook.presto.sql.planner.Plan)

Aggregations

PlanVariableAllocator (com.facebook.presto.sql.planner.PlanVariableAllocator)22 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)9 Test (org.testng.annotations.Test)8 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)7 RowExpression (com.facebook.presto.spi.relation.RowExpression)6 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)6 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 Map (java.util.Map)5 Type (com.facebook.presto.common.type.Type)4 SqlParser (com.facebook.presto.sql.parser.SqlParser)4 ProjectionContext (com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext)4 Expression (com.facebook.presto.sql.tree.Expression)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 List (java.util.List)4 Session (com.facebook.presto.Session)3 Metadata (com.facebook.presto.metadata.Metadata)3 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Optional (java.util.Optional)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2