use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestParameterExtractor method testParameterCount.
@Test
public void testParameterCount() {
Statement statement = sqlParser.createStatement("SELECT c1, c2 FROM test_table WHERE c1 = ? AND c2 > ?", new ParsingOptions());
assertThat(ParameterExtractor.getParameters(statement)).containsExactly(new Parameter(new NodeLocation(1, 41), 0), new Parameter(new NodeLocation(1, 52), 1));
assertThat(ParameterExtractor.getParameterCount(statement)).isEqualTo(2);
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestAnalyzer method analyze.
private Analysis analyze(Session clientSession, @Language("SQL") String query, AccessControl accessControl) {
return transaction(transactionManager, accessControl).singleStatement().readUncommitted().execute(clientSession, session -> {
Analyzer analyzer = createAnalyzer(session, accessControl);
Statement statement = SQL_PARSER.createStatement(query, new ParsingOptions(new FeaturesConfig().isParseDecimalLiteralsAsDouble() ? AS_DOUBLE : AS_DECIMAL));
return analyzer.analyze(statement);
});
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestExpressionEquivalence method assertEquivalent.
private static void assertEquivalent(@Language("SQL") String left, @Language("SQL") String right) {
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
Expression leftExpression = planExpression(PLANNER_CONTEXT, TEST_SESSION, TYPE_PROVIDER, SQL_PARSER.createExpression(left, parsingOptions));
Expression rightExpression = planExpression(PLANNER_CONTEXT, TEST_SESSION, TYPE_PROVIDER, SQL_PARSER.createExpression(right, parsingOptions));
Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression));
TypeProvider types = TypeProvider.copyOf(symbols.stream().collect(toMap(identity(), TestExpressionEquivalence::generateType)));
assertTrue(areExpressionEquivalent(leftExpression, rightExpression, types), format("Expected (%s) and (%s) to be equivalent", left, right));
assertTrue(areExpressionEquivalent(rightExpression, leftExpression, types), format("Expected (%s) and (%s) to be equivalent", right, left));
}
use of io.trino.sql.parser.ParsingOptions 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.parser.ParsingOptions 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);
}
Aggregations