Search in sources :

Example 1 with Analyzer

use of io.trino.sql.analyzer.Analyzer in project trino by trinodb.

the class SqlQueryExecution method analyze.

private static Analysis analyze(PreparedQuery preparedQuery, QueryStateMachine stateMachine, WarningCollector warningCollector, AnalyzerFactory analyzerFactory) {
    stateMachine.beginAnalysis();
    requireNonNull(preparedQuery, "preparedQuery is null");
    Analyzer analyzer = analyzerFactory.createAnalyzer(stateMachine.getSession(), preparedQuery.getParameters(), parameterExtractor(preparedQuery.getStatement(), preparedQuery.getParameters()), warningCollector);
    Analysis analysis;
    try {
        analysis = analyzer.analyze(preparedQuery.getStatement());
    } catch (StackOverflowError e) {
        throw new TrinoException(STACK_OVERFLOW, "statement is too large (stack overflow during analysis)", e);
    }
    stateMachine.setUpdateType(analysis.getUpdateType());
    stateMachine.setReferencedTables(analysis.getReferencedTables());
    stateMachine.setRoutines(analysis.getRoutines());
    stateMachine.endAnalysis();
    return analysis;
}
Also used : Analysis(io.trino.sql.analyzer.Analysis) TrinoException(io.trino.spi.TrinoException) Analyzer(io.trino.sql.analyzer.Analyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer)

Example 2 with Analyzer

use of io.trino.sql.analyzer.Analyzer in project trino by trinodb.

the class LocalQueryRunner method createPlan.

public Plan createPlan(Session session, @Language("SQL") String sql, List<PlanOptimizer> optimizers, LogicalPlanner.Stage stage, WarningCollector warningCollector) {
    PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, sql);
    assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    AnalyzerFactory analyzerFactory = createAnalyzerFactory(createQueryExplainerFactory(optimizers));
    Analyzer analyzer = analyzerFactory.createAnalyzer(session, preparedQuery.getParameters(), parameterExtractor(preparedQuery.getStatement(), preparedQuery.getParameters()), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, optimizers, new PlanSanityChecker(true), idAllocator, getPlannerContext(), new TypeAnalyzer(plannerContext, statementAnalyzerFactory), statsCalculator, costCalculator, warningCollector);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    // make LocalQueryRunner always compute plan statistics for test purposes
    return logicalPlanner.plan(analysis, stage);
}
Also used : QueryPreparer(io.trino.execution.QueryPreparer) LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Analysis(io.trino.sql.analyzer.Analysis) PreparedQuery(io.trino.execution.QueryPreparer.PreparedQuery) PlanSanityChecker(io.trino.sql.planner.sanity.PlanSanityChecker) Analyzer(io.trino.sql.analyzer.Analyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory)

Aggregations

Analysis (io.trino.sql.analyzer.Analysis)2 Analyzer (io.trino.sql.analyzer.Analyzer)2 TypeAnalyzer (io.trino.sql.planner.TypeAnalyzer)2 QueryPreparer (io.trino.execution.QueryPreparer)1 PreparedQuery (io.trino.execution.QueryPreparer.PreparedQuery)1 TrinoException (io.trino.spi.TrinoException)1 AnalyzerFactory (io.trino.sql.analyzer.AnalyzerFactory)1 StatementAnalyzerFactory (io.trino.sql.analyzer.StatementAnalyzerFactory)1 LogicalPlanner (io.trino.sql.planner.LogicalPlanner)1 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)1 PlanSanityChecker (io.trino.sql.planner.sanity.PlanSanityChecker)1