Search in sources :

Example 1 with LogicalPlanner

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

the class SqlQueryExecution method doAnalyzeQuery.

private PlanRoot doAnalyzeQuery() {
    // time analysis phase
    long analysisStart = System.nanoTime();
    // analyze query
    Analyzer analyzer = new Analyzer(stateMachine.getSession(), metadata, sqlParser, accessControl, Optional.of(queryExplainer), parameters);
    Analysis analysis = analyzer.analyze(statement);
    stateMachine.setUpdateType(analysis.getUpdateType());
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    LogicalPlanner logicalPlanner = new LogicalPlanner(stateMachine.getSession(), planOptimizers, idAllocator, metadata, sqlParser);
    Plan plan = logicalPlanner.plan(analysis);
    // 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
    SubPlan subplan = PlanFragmenter.createSubPlans(stateMachine.getSession(), metadata, plan);
    // record analysis time
    stateMachine.recordAnalysisTime(analysisStart);
    boolean explainAnalyze = analysis.getStatement() instanceof Explain && ((Explain) analysis.getStatement()).isAnalyze();
    return new PlanRoot(subplan, !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) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) Plan(com.facebook.presto.sql.planner.Plan) SubPlan(com.facebook.presto.sql.planner.SubPlan) OutputExtractor(com.facebook.presto.sql.planner.OutputExtractor) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) Analysis(com.facebook.presto.sql.analyzer.Analysis) SubPlan(com.facebook.presto.sql.planner.SubPlan)

Example 2 with LogicalPlanner

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

the class QueryExplainer method getLogicalPlan.

private Plan getLogicalPlan(Session session, Statement statement, List<Expression> parameters) {
    // analyze statement
    Analysis analysis = analyze(session, statement, parameters);
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    // plan statement
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, planOptimizers, idAllocator, metadata, sqlParser);
    return logicalPlanner.plan(analysis);
}
Also used : LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator)

Example 3 with LogicalPlanner

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

the class LocalQueryRunner method createPlan.

public Plan createPlan(Session session, @Language("SQL") String sql, List<PlanOptimizer> optimizers, LogicalPlanner.Stage stage) {
    Statement wrapped = sqlParser.createStatement(sql);
    Statement statement = unwrapExecuteStatement(wrapped, sqlParser, session);
    List<Expression> parameters = emptyList();
    if (wrapped instanceof Execute) {
        parameters = ((Execute) wrapped).getParameters();
    }
    validateParameters(statement, parameters);
    assertFormattedSql(sqlParser, statement);
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    QueryExplainer queryExplainer = new QueryExplainer(optimizers, metadata, accessControl, sqlParser, dataDefinitionTask);
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), parameters);
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, optimizers, idAllocator, metadata, sqlParser);
    Analysis analysis = analyzer.analyze(statement);
    return logicalPlanner.plan(analysis, stage);
}
Also used : QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) Execute(com.facebook.presto.sql.tree.Execute) Expression(com.facebook.presto.sql.tree.Expression) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) Analysis(com.facebook.presto.sql.analyzer.Analysis) Analyzer(com.facebook.presto.sql.analyzer.Analyzer)

Aggregations

LogicalPlanner (com.facebook.presto.sql.planner.LogicalPlanner)3 PlanNodeIdAllocator (com.facebook.presto.sql.planner.PlanNodeIdAllocator)3 Analysis (com.facebook.presto.sql.analyzer.Analysis)2 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)2 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)1 QueryExplainer (com.facebook.presto.sql.analyzer.QueryExplainer)1 InputExtractor (com.facebook.presto.sql.planner.InputExtractor)1 OutputExtractor (com.facebook.presto.sql.planner.OutputExtractor)1 Plan (com.facebook.presto.sql.planner.Plan)1 StageExecutionPlan (com.facebook.presto.sql.planner.StageExecutionPlan)1 SubPlan (com.facebook.presto.sql.planner.SubPlan)1 Execute (com.facebook.presto.sql.tree.Execute)1 Explain (com.facebook.presto.sql.tree.Explain)1 Expression (com.facebook.presto.sql.tree.Expression)1 Statement (com.facebook.presto.sql.tree.Statement)1