Search in sources :

Example 1 with Explain

use of io.prestosql.sql.tree.Explain in project hetu-core by openlookeng.

the class SqlQueryExecution method doAnalyzeQuery.

private PlanRoot doAnalyzeQuery() {
    // time analysis phase
    stateMachine.beginAnalysis();
    stateMachine.beginLogicalPlan();
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    Plan plan = createPlan(analysis, stateMachine.getSession(), planOptimizers, idAllocator, metadata, new TypeAnalyzer(sqlParser, metadata), statsCalculator, costCalculator, stateMachine.getWarningCollector());
    queryPlan.set(plan);
    // extract inputs
    List<Input> inputs = new InputExtractor(metadata, stateMachine.getSession()).extractInputs(plan.getRoot());
    stateMachine.setInputs(inputs);
    // extract output
    stateMachine.setOutput(analysis.getTarget());
    stateMachine.endLogicalPlan();
    // fragment the plan
    SubPlan fragmentedPlan = planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, stateMachine.getWarningCollector());
    // record analysis time
    stateMachine.endAnalysis();
    boolean explainAnalyze = analysis.getStatement() instanceof Explain && ((Explain) analysis.getStatement()).isAnalyze();
    if (SystemSessionProperties.isSnapshotEnabled(getSession())) {
        checkSnapshotSupport(getSession());
    }
    return new PlanRoot(fragmentedPlan, !explainAnalyze, extractConnectors(analysis));
}
Also used : PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Explain(io.prestosql.sql.tree.Explain) InputExtractor(io.prestosql.sql.planner.InputExtractor) SubPlan(io.prestosql.sql.planner.SubPlan) Plan(io.prestosql.sql.planner.Plan) StageExecutionPlan(io.prestosql.sql.planner.StageExecutionPlan) CachedSqlQueryExecutionPlan(io.prestosql.query.CachedSqlQueryExecutionPlan) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) SubPlan(io.prestosql.sql.planner.SubPlan)

Example 2 with Explain

use of io.prestosql.sql.tree.Explain in project hetu-core by openlookeng.

the class QueryPreparer method prepareQuery.

public PreparedQuery prepareQuery(Session session, Statement wrappedStatement) throws ParsingException, PrestoException, SemanticException {
    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 Explain && ((Explain) statement).isAnalyze()) {
        Statement innerStatement = ((Explain) statement).getStatement();
        Optional<QueryType> innerQueryType = StatementUtils.getQueryType(innerStatement.getClass());
        if (!innerQueryType.isPresent() || innerQueryType.get() == QueryType.DATA_DEFINITION) {
            throw new PrestoException(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.prestosql.sql.tree.Execute) Expression(io.prestosql.sql.tree.Expression) Statement(io.prestosql.sql.tree.Statement) Explain(io.prestosql.sql.tree.Explain) PrestoException(io.prestosql.spi.PrestoException) QueryType(io.prestosql.spi.resourcegroups.QueryType)

Example 3 with Explain

use of io.prestosql.sql.tree.Explain in project hetu-core by openlookeng.

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()), false, false, ImmutableList.of()));
    assertStatement("EXPLAIN ANALYZE ANALYZE foo", new Explain(new Analyze(table, ImmutableList.of()), true, false, ImmutableList.of()));
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) QualifiedName(io.prestosql.sql.tree.QualifiedName) Explain(io.prestosql.sql.tree.Explain) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) FunctionCall(io.prestosql.sql.tree.FunctionCall) Property(io.prestosql.sql.tree.Property) Analyze(io.prestosql.sql.tree.Analyze) Test(org.testng.annotations.Test)

Example 4 with Explain

use of io.prestosql.sql.tree.Explain in project hetu-core by openlookeng.

the class TestSqlParser method testExplain.

@Test
public void testExplain() {
    assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of()));
    assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL))));
    assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT))));
}
Also used : ExplainType(io.prestosql.sql.tree.ExplainType) ExplainFormat(io.prestosql.sql.tree.ExplainFormat) Explain(io.prestosql.sql.tree.Explain) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Aggregations

Explain (io.prestosql.sql.tree.Explain)4 Test (org.testng.annotations.Test)2 CachedSqlQueryExecutionPlan (io.prestosql.query.CachedSqlQueryExecutionPlan)1 PrestoException (io.prestosql.spi.PrestoException)1 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)1 QueryType (io.prestosql.spi.resourcegroups.QueryType)1 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)1 InputExtractor (io.prestosql.sql.planner.InputExtractor)1 Plan (io.prestosql.sql.planner.Plan)1 StageExecutionPlan (io.prestosql.sql.planner.StageExecutionPlan)1 SubPlan (io.prestosql.sql.planner.SubPlan)1 TypeAnalyzer (io.prestosql.sql.planner.TypeAnalyzer)1 AllColumns (io.prestosql.sql.tree.AllColumns)1 Analyze (io.prestosql.sql.tree.Analyze)1 ArrayConstructor (io.prestosql.sql.tree.ArrayConstructor)1 Execute (io.prestosql.sql.tree.Execute)1 ExplainFormat (io.prestosql.sql.tree.ExplainFormat)1 ExplainType (io.prestosql.sql.tree.ExplainType)1 Expression (io.prestosql.sql.tree.Expression)1 FunctionCall (io.prestosql.sql.tree.FunctionCall)1