use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestSimplifyExpressions method assertSimplifies.
private static void assertSimplifies(@Language("SQL") String expression, @Language("SQL") String expected) {
Expression expectedExpression = normalize(rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expected, new ParsingOptions())));
assertEquals(simplify(expression), expectedExpression);
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestExpressionEquivalence method assertNotEquivalent.
private static void assertNotEquivalent(@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)));
assertFalse(areExpressionEquivalent(leftExpression, rightExpression, types), format("Expected (%s) and (%s) to not be equivalent", left, right));
assertFalse(areExpressionEquivalent(rightExpression, leftExpression, types), format("Expected (%s) and (%s) to not be equivalent", right, left));
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TreeAssertions method assertFormattedSql.
public static void assertFormattedSql(SqlParser sqlParser, Node expected) {
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
assertFormattedSql(sqlParser, parsingOptions, expected);
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestExpressionInterpreter method assertOptimizedMatches.
private static void assertOptimizedMatches(@Language("SQL") String actual, @Language("SQL") String expected) {
Expression actualOptimized = (Expression) optimize(actual);
SymbolAliases.Builder aliases = SymbolAliases.builder().putAll(SYMBOL_TYPES.allTypes().keySet().stream().map(Symbol::getName).collect(toImmutableMap(identity(), SymbolReference::new)));
Expression rewrittenExpected = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expected, new ParsingOptions()));
assertExpressionEquals(actualOptimized, rewrittenExpected, aliases.build());
}
use of io.trino.sql.parser.ParsingOptions in project trino by trinodb.
the class TestExpressionInterpreter method assertRoundTrip.
private static void assertRoundTrip(String expression) {
ParsingOptions parsingOptions = createParsingOptions(TEST_SESSION);
Expression parsed = SQL_PARSER.createExpression(expression, parsingOptions);
String formatted = formatExpression(parsed);
assertEquals(parsed, SQL_PARSER.createExpression(formatted, parsingOptions));
}
Aggregations