Search in sources :

Example 1 with Execute

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

the class PrepareTask method execute.

@Override
public ListenableFuture<Void> execute(Prepare prepare, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Statement statement = prepare.getStatement();
    if ((statement instanceof Prepare) || (statement instanceof Execute) || (statement instanceof Deallocate)) {
        String type = statement.getClass().getSimpleName().toUpperCase(ENGLISH);
        throw new TrinoException(NOT_SUPPORTED, "Invalid statement type for prepared statement: " + type);
    }
    String sql = getFormattedSql(statement, sqlParser);
    stateMachine.addPreparedStatement(prepare.getName().getValue(), sql);
    return immediateVoidFuture();
}
Also used : Execute(io.trino.sql.tree.Execute) Deallocate(io.trino.sql.tree.Deallocate) Statement(io.trino.sql.tree.Statement) Prepare(io.trino.sql.tree.Prepare) TrinoException(io.trino.spi.TrinoException)

Example 2 with Execute

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

the class TestPrepareTask method testPrepareInvalidStatement.

@Test
public void testPrepareInvalidStatement() {
    Statement statement = new Execute(identifier("foo"), emptyList());
    String sqlString = "PREPARE my_query FROM EXECUTE foo";
    assertTrinoExceptionThrownBy(() -> executePrepare("my_query", statement, sqlString, TEST_SESSION)).hasErrorCode(NOT_SUPPORTED).hasMessage("Invalid statement type for prepared statement: EXECUTE");
}
Also used : Execute(io.trino.sql.tree.Execute) Statement(io.trino.sql.tree.Statement) Test(org.testng.annotations.Test)

Example 3 with Execute

use of io.trino.sql.tree.Execute 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

Execute (io.trino.sql.tree.Execute)3 Statement (io.trino.sql.tree.Statement)3 TrinoException (io.trino.spi.TrinoException)2 QueryType (io.trino.spi.resourcegroups.QueryType)1 Deallocate (io.trino.sql.tree.Deallocate)1 ExplainAnalyze (io.trino.sql.tree.ExplainAnalyze)1 Expression (io.trino.sql.tree.Expression)1 Prepare (io.trino.sql.tree.Prepare)1 StatementUtils.getQueryType (io.trino.util.StatementUtils.getQueryType)1 Test (org.testng.annotations.Test)1