Search in sources :

Example 1 with OutputExtractor

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

the class PrestoSparkQueryPlanner method createQueryPlan.

public PlanAndMore createQueryPlan(Session session, PreparedQuery preparedQuery, WarningCollector warningCollector) {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(false, session, optimizers.getPlanningTimeOptimizers(), idAllocator, metadata, sqlParser, statsCalculator, costCalculator, warningCollector, planChecker);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    Plan plan = logicalPlanner.plan(analysis, OPTIMIZED_AND_VALIDATED);
    List<Input> inputs = new InputExtractor(metadata, session).extractInputs(plan.getRoot());
    Optional<Output> output = new OutputExtractor().extractOutput(plan.getRoot());
    Optional<QueryType> queryType = getQueryType(preparedQuery.getStatement().getClass());
    List<String> columnNames = ((OutputNode) plan.getRoot()).getColumnNames();
    return new PlanAndMore(plan, Optional.ofNullable(analysis.getUpdateType()), columnNames, ImmutableSet.copyOf(inputs), output, queryType);
}
Also used : OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) InputExtractor(com.facebook.presto.sql.planner.InputExtractor) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) Plan(com.facebook.presto.sql.planner.Plan) Input(com.facebook.presto.execution.Input) OutputExtractor(com.facebook.presto.sql.planner.OutputExtractor) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Analysis(com.facebook.presto.sql.analyzer.Analysis) Output(com.facebook.presto.execution.Output) StatementUtils.getQueryType(com.facebook.presto.util.StatementUtils.getQueryType) QueryType(com.facebook.presto.spi.resourceGroups.QueryType)

Example 2 with OutputExtractor

use of com.facebook.presto.sql.planner.OutputExtractor 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

InputExtractor (com.facebook.presto.sql.planner.InputExtractor)2 LogicalPlanner (com.facebook.presto.sql.planner.LogicalPlanner)2 OutputExtractor (com.facebook.presto.sql.planner.OutputExtractor)2 Plan (com.facebook.presto.sql.planner.Plan)2 Input (com.facebook.presto.execution.Input)1 Output (com.facebook.presto.execution.Output)1 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)1 QueryType (com.facebook.presto.spi.resourceGroups.QueryType)1 Analysis (com.facebook.presto.sql.analyzer.Analysis)1 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)1 PlanVariableAllocator (com.facebook.presto.sql.planner.PlanVariableAllocator)1 SubPlan (com.facebook.presto.sql.planner.SubPlan)1 OutputNode (com.facebook.presto.sql.planner.plan.OutputNode)1 Explain (com.facebook.presto.sql.tree.Explain)1 StatementUtils.getQueryType (com.facebook.presto.util.StatementUtils.getQueryType)1