Search in sources :

Example 11 with ParsingOptions

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);
}
Also used : ExpressionUtils.logicalExpression(io.trino.sql.ExpressionUtils.logicalExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) Expression(io.trino.sql.tree.Expression) ParsingOptions(io.trino.sql.parser.ParsingOptions)

Example 12 with ParsingOptions

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));
}
Also used : ParsingOptions(io.trino.sql.parser.ParsingOptions) ExpressionTestUtils.planExpression(io.trino.sql.ExpressionTestUtils.planExpression) Expression(io.trino.sql.tree.Expression) Symbol(io.trino.sql.planner.Symbol) TypeProvider(io.trino.sql.planner.TypeProvider)

Example 13 with ParsingOptions

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);
}
Also used : ParsingOptions(io.trino.sql.parser.ParsingOptions)

Example 14 with ParsingOptions

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());
}
Also used : ExpressionFormatter.formatExpression(io.trino.sql.ExpressionFormatter.formatExpression) Expression(io.trino.sql.tree.Expression) ParsingUtil.createParsingOptions(io.trino.sql.ParsingUtil.createParsingOptions) ParsingOptions(io.trino.sql.parser.ParsingOptions) SymbolAliases(io.trino.sql.planner.assertions.SymbolAliases) Symbol(io.trino.sql.planner.Symbol) SymbolReference(io.trino.sql.tree.SymbolReference)

Example 15 with ParsingOptions

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));
}
Also used : ParsingUtil.createParsingOptions(io.trino.sql.ParsingUtil.createParsingOptions) ParsingOptions(io.trino.sql.parser.ParsingOptions) ExpressionFormatter.formatExpression(io.trino.sql.ExpressionFormatter.formatExpression) Expression(io.trino.sql.tree.Expression)

Aggregations

ParsingOptions (io.trino.sql.parser.ParsingOptions)15 Expression (io.trino.sql.tree.Expression)6 Statement (io.trino.sql.tree.Statement)6 Test (org.testng.annotations.Test)4 Symbol (io.trino.sql.planner.Symbol)3 NodeLocation (io.trino.sql.tree.NodeLocation)3 Parameter (io.trino.sql.tree.Parameter)3 ExpressionFormatter.formatExpression (io.trino.sql.ExpressionFormatter.formatExpression)2 ExpressionTestUtils.planExpression (io.trino.sql.ExpressionTestUtils.planExpression)2 ExpressionUtils.logicalExpression (io.trino.sql.ExpressionUtils.logicalExpression)2 ParsingUtil.createParsingOptions (io.trino.sql.ParsingUtil.createParsingOptions)2 ParsingException (io.trino.sql.parser.ParsingException)2 TypeProvider (io.trino.sql.planner.TypeProvider)2 LogicalExpression (io.trino.sql.tree.LogicalExpression)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 FeaturesConfig (io.trino.FeaturesConfig)1 ResourceGroupId (io.trino.spi.resourcegroups.ResourceGroupId)1 SqlParser (io.trino.sql.parser.SqlParser)1 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)1