Search in sources :

Example 1 with QueryType

use of io.trino.spi.resourcegroups.QueryType 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)

Aggregations

TrinoException (io.trino.spi.TrinoException)1 QueryType (io.trino.spi.resourcegroups.QueryType)1 Execute (io.trino.sql.tree.Execute)1 ExplainAnalyze (io.trino.sql.tree.ExplainAnalyze)1 Expression (io.trino.sql.tree.Expression)1 Statement (io.trino.sql.tree.Statement)1 StatementUtils.getQueryType (io.trino.util.StatementUtils.getQueryType)1