Search in sources :

Example 26 with NullLiteral

use of io.trino.sql.tree.NullLiteral in project trino by trinodb.

the class TestSqlParser method testIf.

@Test
public void testIf() {
    assertExpression("if(true, 1, 0)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("1"), new LongLiteral("0")));
    assertExpression("if(true, 3, null)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), new NullLiteral()));
    assertExpression("if(false, null, 4)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new LongLiteral("4")));
    assertExpression("if(false, null, null)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new NullLiteral()));
    assertExpression("if(true, 3)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), null));
    assertInvalidExpression("IF(true)", "Invalid number of arguments for 'if' function");
    assertInvalidExpression("IF(true, 1, 0) FILTER (WHERE true)", "FILTER not valid for 'if' function");
    assertInvalidExpression("IF(true, 1, 0) OVER()", "OVER clause not valid for 'if' function");
}
Also used : NullIfExpression(io.trino.sql.tree.NullIfExpression) IfExpression(io.trino.sql.tree.IfExpression) LongLiteral(io.trino.sql.tree.LongLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) NullLiteral(io.trino.sql.tree.NullLiteral) Test(org.junit.jupiter.api.Test)

Aggregations

NullLiteral (io.trino.sql.tree.NullLiteral)26 Expression (io.trino.sql.tree.Expression)13 Test (org.testng.annotations.Test)13 Symbol (io.trino.sql.planner.Symbol)12 Cast (io.trino.sql.tree.Cast)11 IfExpression (io.trino.sql.tree.IfExpression)10 ImmutableList (com.google.common.collect.ImmutableList)9 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)9 ImmutableMap (com.google.common.collect.ImmutableMap)7 Type (io.trino.spi.type.Type)7 ResolvedFunction (io.trino.metadata.ResolvedFunction)6 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)6 Assignments (io.trino.sql.planner.plan.Assignments)6 LongLiteral (io.trino.sql.tree.LongLiteral)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ProjectNode (io.trino.sql.planner.plan.ProjectNode)5 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)5 FunctionCall (io.trino.sql.tree.FunctionCall)5 Row (io.trino.sql.tree.Row)5 Optional (java.util.Optional)5