Search in sources :

Example 1 with QueryExplainer

use of com.facebook.presto.sql.analyzer.QueryExplainer 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)

Example 2 with QueryExplainer

use of com.facebook.presto.sql.analyzer.QueryExplainer in project presto by prestodb.

the class AbstractTestQueryFramework method assertPlan.

protected void assertPlan(Session session, @Language("SQL") String query, PlanMatchPattern pattern, Consumer<Plan> planValidator) {
    QueryExplainer explainer = getQueryExplainer();
    transaction(queryRunner.getTransactionManager(), queryRunner.getAccessControl()).singleStatement().execute(session, transactionSession -> {
        Plan actualPlan = explainer.getLogicalPlan(transactionSession, sqlParser.createStatement(query, createParsingOptions(transactionSession)), emptyList(), WarningCollector.NOOP);
        PlanAssert.assertPlan(transactionSession, queryRunner.getMetadata(), queryRunner.getStatsCalculator(), actualPlan, pattern);
        planValidator.accept(actualPlan);
        return null;
    });
}
Also used : QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) Plan(com.facebook.presto.sql.planner.Plan) SubPlan(com.facebook.presto.sql.planner.SubPlan)

Example 3 with QueryExplainer

use of com.facebook.presto.sql.analyzer.QueryExplainer 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, WarningCollector warningCollector) {
    Statement wrappedStatement = sqlParser.createStatement(sql, createParsingOptions(session, warningCollector));
    PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, wrappedStatement, warningCollector);
    assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    QueryExplainer queryExplainer = new QueryExplainer(optimizers, planFragmenter, metadata, accessControl, sqlParser, statsCalculator, costCalculator, dataDefinitionTask, distributedPlanChecker);
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(wrappedStatement instanceof Explain, session, optimizers, singleNodePlanChecker, idAllocator, metadata, sqlParser, statsCalculator, costCalculator, warningCollector);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    return logicalPlanner.plan(analysis, stage);
}
Also used : QueryPreparer(com.facebook.presto.execution.QueryPreparer) QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Statement(com.facebook.presto.sql.tree.Statement) Analysis(com.facebook.presto.sql.analyzer.Analysis) Explain(com.facebook.presto.sql.tree.Explain) PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) Analyzer(com.facebook.presto.sql.analyzer.Analyzer)

Example 4 with QueryExplainer

use of com.facebook.presto.sql.analyzer.QueryExplainer in project presto by prestodb.

the class AbstractTestQueryFramework method getQueryExplainer.

private QueryExplainer getQueryExplainer() {
    Metadata metadata = queryRunner.getMetadata();
    FeaturesConfig featuresConfig = new FeaturesConfig().setOptimizeHashGeneration(true);
    boolean forceSingleNode = queryRunner.getNodeCount() == 1;
    TaskCountEstimator taskCountEstimator = new TaskCountEstimator(queryRunner::getNodeCount);
    CostCalculator costCalculator = new CostCalculatorUsingExchanges(taskCountEstimator);
    List<PlanOptimizer> optimizers = new PlanOptimizers(metadata, sqlParser, forceSingleNode, new MBeanExporter(new TestingMBeanServer()), queryRunner.getSplitManager(), queryRunner.getPlanOptimizerManager(), queryRunner.getPageSourceManager(), queryRunner.getStatsCalculator(), costCalculator, new CostCalculatorWithEstimatedExchanges(costCalculator, taskCountEstimator), new CostComparator(featuresConfig), taskCountEstimator, new PartitioningProviderManager()).getPlanningTimeOptimizers();
    return new QueryExplainer(optimizers, new PlanFragmenter(metadata, queryRunner.getNodePartitioningManager(), new QueryManagerConfig(), sqlParser, new FeaturesConfig()), metadata, queryRunner.getAccessControl(), sqlParser, queryRunner.getStatsCalculator(), costCalculator, ImmutableMap.of(), new PlanChecker(new FeaturesConfig(), false));
}
Also used : TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) CostComparator(com.facebook.presto.cost.CostComparator) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) TestingMBeanServer(org.weakref.jmx.testing.TestingMBeanServer) QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) MBeanExporter(org.weakref.jmx.MBeanExporter) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) Metadata(com.facebook.presto.metadata.Metadata) PlanFragmenter(com.facebook.presto.sql.planner.PlanFragmenter) CostCalculator(com.facebook.presto.cost.CostCalculator) PlanChecker(com.facebook.presto.sql.planner.sanity.PlanChecker) PlanOptimizers(com.facebook.presto.sql.planner.PlanOptimizers) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) CostCalculatorUsingExchanges(com.facebook.presto.cost.CostCalculatorUsingExchanges) CostCalculatorWithEstimatedExchanges(com.facebook.presto.cost.CostCalculatorWithEstimatedExchanges)

Aggregations

QueryExplainer (com.facebook.presto.sql.analyzer.QueryExplainer)4 Analysis (com.facebook.presto.sql.analyzer.Analysis)2 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)2 LogicalPlanner (com.facebook.presto.sql.planner.LogicalPlanner)2 Statement (com.facebook.presto.sql.tree.Statement)2 CostCalculator (com.facebook.presto.cost.CostCalculator)1 CostCalculatorUsingExchanges (com.facebook.presto.cost.CostCalculatorUsingExchanges)1 CostCalculatorWithEstimatedExchanges (com.facebook.presto.cost.CostCalculatorWithEstimatedExchanges)1 CostComparator (com.facebook.presto.cost.CostComparator)1 TaskCountEstimator (com.facebook.presto.cost.TaskCountEstimator)1 QueryManagerConfig (com.facebook.presto.execution.QueryManagerConfig)1 QueryPreparer (com.facebook.presto.execution.QueryPreparer)1 PreparedQuery (com.facebook.presto.execution.QueryPreparer.PreparedQuery)1 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)1 Metadata (com.facebook.presto.metadata.Metadata)1 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)1 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)1 PartitioningProviderManager (com.facebook.presto.sql.planner.PartitioningProviderManager)1 Plan (com.facebook.presto.sql.planner.Plan)1 PlanFragmenter (com.facebook.presto.sql.planner.PlanFragmenter)1