Search in sources :

Example 1 with ExpressionVerifier

use of io.trino.sql.planner.assertions.ExpressionVerifier in project trino by trinodb.

the class TestDesugarTryExpressionRewriter method testTryExpressionDesugaringRewriter.

@Test
public void testTryExpressionDesugaringRewriter() {
    // 1 + try(2)
    Expression initial = new ArithmeticBinaryExpression(ADD, new DecimalLiteral("1"), new TryExpression(new DecimalLiteral("2")));
    Expression rewritten = DesugarTryExpressionRewriter.rewrite(initial, tester().getMetadata(), tester().getTypeAnalyzer(), tester().getSession(), new SymbolAllocator());
    // 1 + try_function(() -> 2)
    Expression expected = new ArithmeticBinaryExpression(ADD, new DecimalLiteral("1"), new TestingFunctionResolution().functionCallBuilder(QualifiedName.of(TryFunction.NAME)).addArgument(new FunctionType(ImmutableList.of(), createDecimalType(1)), new LambdaExpression(ImmutableList.of(), new DecimalLiteral("2"))).build());
    ExpressionVerifier verifier = new ExpressionVerifier(new SymbolAliases());
    assertTrue(verifier.process(rewritten, expected));
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) LambdaExpression(io.trino.sql.tree.LambdaExpression) Expression(io.trino.sql.tree.Expression) TryExpression(io.trino.sql.tree.TryExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) SymbolAliases(io.trino.sql.planner.assertions.SymbolAliases) FunctionType(io.trino.type.FunctionType) ExpressionVerifier(io.trino.sql.planner.assertions.ExpressionVerifier) DecimalLiteral(io.trino.sql.tree.DecimalLiteral) TryExpression(io.trino.sql.tree.TryExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Aggregations

TestingFunctionResolution (io.trino.metadata.TestingFunctionResolution)1 ExpressionVerifier (io.trino.sql.planner.assertions.ExpressionVerifier)1 SymbolAliases (io.trino.sql.planner.assertions.SymbolAliases)1 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)1 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)1 DecimalLiteral (io.trino.sql.tree.DecimalLiteral)1 Expression (io.trino.sql.tree.Expression)1 LambdaExpression (io.trino.sql.tree.LambdaExpression)1 TryExpression (io.trino.sql.tree.TryExpression)1 FunctionType (io.trino.type.FunctionType)1 Test (org.testng.annotations.Test)1