Search in sources :

Example 1 with PlanVariableAllocator

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

the class TestRemoveUnsupportedDynamicFilters method removeUnsupportedDynamicFilters.

PlanNode removeUnsupportedDynamicFilters(PlanNode root) {
    return getQueryRunner().inTransaction(session -> {
        // metadata.getCatalogHandle() registers the catalog for the transaction
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        PlanNode rewrittenPlan = new RemoveUnsupportedDynamicFilters(metadata.getFunctionAndTypeManager()).optimize(root, session, TypeProvider.empty(), new PlanVariableAllocator(), new PlanNodeIdAllocator(), WarningCollector.NOOP);
        new DynamicFiltersChecker().validate(rewrittenPlan, session, metadata, new SqlParser(), TypeProvider.empty(), WarningCollector.NOOP);
        return rewrittenPlan;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) SqlParser(com.facebook.presto.sql.parser.SqlParser) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) DynamicFiltersChecker(com.facebook.presto.sql.planner.sanity.DynamicFiltersChecker) RemoveUnsupportedDynamicFilters(com.facebook.presto.sql.planner.iterative.rule.RemoveUnsupportedDynamicFilters)

Example 2 with PlanVariableAllocator

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

the class TestWindowNode method setUp.

@BeforeClass
public void setUp() {
    variableAllocator = new PlanVariableAllocator();
    columnA = variableAllocator.newVariable("a", BIGINT);
    columnB = variableAllocator.newVariable("b", BIGINT);
    columnC = variableAllocator.newVariable("c", BIGINT);
    sourceNode = new ValuesNode(Optional.empty(), newId(), ImmutableList.of(columnA, columnB, columnC), ImmutableList.of());
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with PlanVariableAllocator

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

the class TestPinotPlanOptimizer method getOptimizedPlan.

protected PlanNode getOptimizedPlan(PinotConfig pinotConfig, PlanBuilder planBuilder, PlanNode originalPlan) {
    PinotQueryGenerator pinotQueryGenerator = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution);
    PinotPlanOptimizer optimizer = new PinotPlanOptimizer(pinotQueryGenerator, functionAndTypeManager, functionAndTypeManager, logicalRowExpressions, standardFunctionResolution);
    return optimizer.optimize(originalPlan, new SessionHolder(pinotConfig).getConnectorSession(), new PlanVariableAllocator(), planBuilder.getIdAllocator());
}
Also used : PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PinotPlanOptimizer(com.facebook.presto.pinot.PinotPlanOptimizer)

Example 4 with PlanVariableAllocator

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

the class TestDruidPlanOptimizer method testUnionAll.

@Test
public void testUnionAll() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
    AggregationNode aggregationOne = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableOne, city, fare), variableAllocator, ImmutableList.of(city), fare);
    AggregationNode aggregationTwo = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableTwo, city, fare), variableAllocator, ImmutableList.of(city), fare);
    VariableReferenceExpression groupByColumn = variableAllocator.newVariable(city.getColumnName(), city.getColumnType());
    VariableReferenceExpression sumColumn = variableAllocator.newVariable(fare.getColumnName(), fare.getColumnType());
    PlanNode originalPlan = new UnionNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), ImmutableList.of(aggregationOne, aggregationTwo), ImmutableList.of(groupByColumn, sumColumn), ImmutableMap.of(groupByColumn, Stream.concat(aggregationOne.getGroupingKeys().stream(), aggregationTwo.getGroupingKeys().stream()).collect(toImmutableList()), sumColumn, ImmutableList.of(Iterables.getOnlyElement(aggregationOne.getAggregations().keySet()), Iterables.getOnlyElement(aggregationTwo.getAggregations().keySet()))));
    PlanNode optimizedPlan = getOptimizedPlan(planBuilder, originalPlan);
    PlanMatchPattern tableScanMatcherOne = DruidTableScanMatcher.match(druidTableOne.getTableName(), "SELECT \"city\", sum(fare) FROM \"realtimeOnly\" GROUP BY \"city\"");
    PlanMatchPattern tableScanMatcherTwo = DruidTableScanMatcher.match(druidTableTwo.getTableName(), "SELECT \"city\", sum(fare) FROM \"hybrid\" GROUP BY \"city\"");
    assertPlanMatch(optimizedPlan, PlanMatchPattern.union(tableScanMatcherOne, tableScanMatcherTwo), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) UnionNode(com.facebook.presto.spi.plan.UnionNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 5 with PlanVariableAllocator

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

the class SqlQueryExecution method doAnalyzeQuery.

private PlanRoot doAnalyzeQuery() {
    // time analysis phase
    stateMachine.beginAnalysis();
    // plan query
    LogicalPlanner logicalPlanner = new LogicalPlanner(false, stateMachine.getSession(), planOptimizers, idAllocator, metadata, sqlParser, statsCalculator, costCalculator, stateMachine.getWarningCollector(), planChecker);
    Plan plan = getSession().getRuntimeStats().profileNanos(LOGICAL_PLANNER_TIME_NANOS, () -> logicalPlanner.plan(analysis));
    queryPlan.set(plan);
    // extract inputs
    List<Input> inputs = new InputExtractor(metadata, stateMachine.getSession()).extractInputs(plan.getRoot());
    stateMachine.setInputs(inputs);
    // extract output
    Optional<Output> output = new OutputExtractor().extractOutput(plan.getRoot());
    stateMachine.setOutput(output);
    // fragment the plan
    // the variableAllocator is finally passed to SqlQueryScheduler for runtime cost-based optimizations
    variableAllocator.set(new PlanVariableAllocator(plan.getTypes().allVariables()));
    SubPlan fragmentedPlan = getSession().getRuntimeStats().profileNanos(FRAGMENT_PLAN_TIME_NANOS, () -> planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, idAllocator, variableAllocator.get(), stateMachine.getWarningCollector()));
    // record analysis time
    stateMachine.endAnalysis();
    boolean explainAnalyze = analysis.getStatement() instanceof Explain && ((Explain) analysis.getStatement()).isAnalyze();
    return new PlanRoot(fragmentedPlan, !explainAnalyze, extractConnectors(analysis));
}
Also used : LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) Explain(com.facebook.presto.sql.tree.Explain) InputExtractor(com.facebook.presto.sql.planner.InputExtractor) Plan(com.facebook.presto.sql.planner.Plan) SubPlan(com.facebook.presto.sql.planner.SubPlan) OutputExtractor(com.facebook.presto.sql.planner.OutputExtractor) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) SubPlan(com.facebook.presto.sql.planner.SubPlan)

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