Search in sources :

Example 1 with ExplainAnalyze

use of io.trino.sql.tree.ExplainAnalyze in project trino by trinodb.

the class SqlQueryExecution method doPlanQuery.

private PlanRoot doPlanQuery() {
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    LogicalPlanner logicalPlanner = new LogicalPlanner(stateMachine.getSession(), planOptimizers, idAllocator, plannerContext, typeAnalyzer, statsCalculator, costCalculator, stateMachine.getWarningCollector());
    Plan plan = logicalPlanner.plan(analysis);
    queryPlan.set(plan);
    // fragment the plan
    SubPlan fragmentedPlan = planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, stateMachine.getWarningCollector());
    // extract inputs
    List<Input> inputs = new InputExtractor(plannerContext.getMetadata(), stateMachine.getSession()).extractInputs(fragmentedPlan);
    stateMachine.setInputs(inputs);
    stateMachine.setOutput(analysis.getTarget());
    boolean explainAnalyze = analysis.getStatement() instanceof ExplainAnalyze;
    return new PlanRoot(fragmentedPlan, !explainAnalyze);
}
Also used : LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) InputExtractor(io.trino.sql.planner.InputExtractor) SubPlan(io.trino.sql.planner.SubPlan) Plan(io.trino.sql.planner.Plan) SubPlan(io.trino.sql.planner.SubPlan)

Example 2 with ExplainAnalyze

use of io.trino.sql.tree.ExplainAnalyze in project trino by trinodb.

the class TestSqlParser method testAnalyze.

@Test
public void testAnalyze() {
    QualifiedName table = QualifiedName.of("foo");
    assertStatement("ANALYZE foo", new Analyze(table, ImmutableList.of()));
    assertStatement("ANALYZE foo WITH ( \"string\" = 'bar', \"long\" = 42, computed = concat('ban', 'ana'), a = ARRAY[ 'v1', 'v2' ] )", new Analyze(table, ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))))));
    assertStatement("EXPLAIN ANALYZE foo", new Explain(new Analyze(table, ImmutableList.of()), ImmutableList.of()));
    assertStatement("EXPLAIN ANALYZE ANALYZE foo", new ExplainAnalyze(new Analyze(table, ImmutableList.of()), false));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) QualifiedName(io.trino.sql.tree.QualifiedName) Explain(io.trino.sql.tree.Explain) ArrayConstructor(io.trino.sql.tree.ArrayConstructor) FunctionCall(io.trino.sql.tree.FunctionCall) Property(io.trino.sql.tree.Property) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) Analyze(io.trino.sql.tree.Analyze) Test(org.junit.jupiter.api.Test)

Example 3 with ExplainAnalyze

use of io.trino.sql.tree.ExplainAnalyze in project trino by trinodb.

the class QueryPreparer method prepareQuery.

public PreparedQuery prepareQuery(Session session, Statement wrappedStatement) throws ParsingException, TrinoException {
    Statement statement = wrappedStatement;
    Optional<String> prepareSql = Optional.empty();
    if (statement instanceof Execute) {
        prepareSql = Optional.of(session.getPreparedStatementFromExecute((Execute) statement));
        statement = sqlParser.createStatement(prepareSql.get(), createParsingOptions(session));
    }
    if (statement instanceof ExplainAnalyze) {
        Statement innerStatement = ((ExplainAnalyze) statement).getStatement();
        Optional<QueryType> innerQueryType = getQueryType(innerStatement);
        if (innerQueryType.isEmpty() || innerQueryType.get() == QueryType.DATA_DEFINITION) {
            throw new TrinoException(NOT_SUPPORTED, "EXPLAIN ANALYZE doesn't support statement type: " + innerStatement.getClass().getSimpleName());
        }
    }
    List<Expression> parameters = ImmutableList.of();
    if (wrappedStatement instanceof Execute) {
        parameters = ((Execute) wrappedStatement).getParameters();
    }
    validateParameters(statement, parameters);
    return new PreparedQuery(statement, parameters, prepareSql);
}
Also used : Execute(io.trino.sql.tree.Execute) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) Expression(io.trino.sql.tree.Expression) Statement(io.trino.sql.tree.Statement) TrinoException(io.trino.spi.TrinoException) QueryType(io.trino.spi.resourcegroups.QueryType) StatementUtils.getQueryType(io.trino.util.StatementUtils.getQueryType)

Example 4 with ExplainAnalyze

use of io.trino.sql.tree.ExplainAnalyze in project trino by trinodb.

the class TestSqlParser method testExplainAnalyze.

@Test
public void testExplainAnalyze() {
    assertStatement("EXPLAIN ANALYZE SELECT * FROM t", new ExplainAnalyze(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false));
    assertStatement("EXPLAIN ANALYZE VERBOSE SELECT * FROM t", new ExplainAnalyze(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true));
    assertStatementIsInvalid("EXPLAIN ANALYZE (type DISTRIBUTED) SELECT * FROM t").withMessage("line 1:18: mismatched input 'type'. Expecting: '(', 'SELECT', 'TABLE', 'VALUES'");
    assertStatementIsInvalid("EXPLAIN ANALYZE VERBOSE (type DISTRIBUTED) SELECT * FROM t").withMessage("line 1:26: mismatched input 'type'. Expecting: '(', 'SELECT', 'TABLE', 'VALUES'");
}
Also used : ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Aggregations

ExplainAnalyze (io.trino.sql.tree.ExplainAnalyze)4 Test (org.junit.jupiter.api.Test)2 TrinoException (io.trino.spi.TrinoException)1 QueryType (io.trino.spi.resourcegroups.QueryType)1 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)1 InputExtractor (io.trino.sql.planner.InputExtractor)1 LogicalPlanner (io.trino.sql.planner.LogicalPlanner)1 Plan (io.trino.sql.planner.Plan)1 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)1 SubPlan (io.trino.sql.planner.SubPlan)1 AllColumns (io.trino.sql.tree.AllColumns)1 Analyze (io.trino.sql.tree.Analyze)1 ArrayConstructor (io.trino.sql.tree.ArrayConstructor)1 Execute (io.trino.sql.tree.Execute)1 Explain (io.trino.sql.tree.Explain)1 Expression (io.trino.sql.tree.Expression)1 FunctionCall (io.trino.sql.tree.FunctionCall)1 Identifier (io.trino.sql.tree.Identifier)1 LongLiteral (io.trino.sql.tree.LongLiteral)1 Property (io.trino.sql.tree.Property)1