Search in sources :

Example 11 with BooleanLiteral

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

the class TestSqlParser method testSetTableProperties.

@Test
public void testSetTableProperties() {
    assertStatement("ALTER TABLE a SET PROPERTIES foo='bar'", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new StringLiteral("bar")))));
    assertStatement("ALTER TABLE a SET PROPERTIES foo=true", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new BooleanLiteral("true")))));
    assertStatement("ALTER TABLE a SET PROPERTIES foo=123", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")))));
    assertStatement("ALTER TABLE a SET PROPERTIES foo=123, bar=456", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar"), new LongLiteral("456")))));
    assertStatement("ALTER TABLE a SET PROPERTIES \" s p a c e \"='bar'", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier(" s p a c e "), new StringLiteral("bar")))));
    assertStatement("ALTER TABLE a SET PROPERTIES foo=123, bar=DEFAULT", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar")))));
    assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES").withMessage("line 1:29: mismatched input '<EOF>'. Expecting: <identifier>");
    assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES ()").withMessage("line 1:30: mismatched input '('. Expecting: <identifier>");
    assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES (foo='bar')").withMessage("line 1:30: mismatched input '('. Expecting: <identifier>");
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.Test)

Example 12 with BooleanLiteral

use of io.trino.sql.tree.BooleanLiteral 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

BooleanLiteral (io.trino.sql.tree.BooleanLiteral)12 StringLiteral (io.trino.sql.tree.StringLiteral)10 LongLiteral (io.trino.sql.tree.LongLiteral)8 FunctionCall (io.trino.sql.tree.FunctionCall)6 Test (org.junit.jupiter.api.Test)6 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)4 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)4 Expression (io.trino.sql.tree.Expression)4 NullLiteral (io.trino.sql.tree.NullLiteral)4 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)3 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)3 Identifier (io.trino.sql.tree.Identifier)3 ImmutableList (com.google.common.collect.ImmutableList)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 RowType (io.trino.spi.type.RowType)2 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)2 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)2 Symbol (io.trino.sql.planner.Symbol)2 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)2 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)2