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);
}
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));
}
Aggregations