use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TestParameterExtractor method testNoParameter.
@Test
public void testNoParameter() {
Statement statement = sqlParser.createStatement("SELECT c1, c2 FROM test_table WHERE c1 = 1 AND c2 > 2", new ParsingOptions());
assertThat(ParameterExtractor.getParameters(statement)).isEmpty();
assertThat(ParameterExtractor.getParameterCount(statement)).isEqualTo(0);
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TestParameterExtractor method testLambda.
@Test
public void testLambda() {
Statement statement = sqlParser.createStatement("SELECT * FROM test_table WHERE any_match(items, x -> x > ?)", new ParsingOptions());
assertThat(ParameterExtractor.getParameters(statement)).containsExactly(new Parameter(new NodeLocation(1, 58), 0));
assertThat(ParameterExtractor.getParameterCount(statement)).isEqualTo(1);
}
use of io.trino.sql.tree.Statement 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);
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TestStatementBuilder method printStatement.
private static void printStatement(String sql) {
println(sql.trim());
println("");
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
Statement statement = SQL_PARSER.createStatement(sql, parsingOptions);
println(statement.toString());
println("");
println(SqlFormatter.formatSql(statement));
println("");
assertFormattedSql(SQL_PARSER, statement);
println(repeat("=", 60));
println("");
}
Aggregations