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();
}
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");
}
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);
}
Aggregations