Search in sources :

Example 26 with Identifier

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

the class TestSqlParser method testAllRowsReference.

@Test
public void testAllRowsReference() {
    assertThatThrownBy(() -> SQL_PARSER.createStatement("SELECT 1 + A.*", new ParsingOptions(REJECT))).isInstanceOf(ParsingException.class).hasMessageMatching("line 1:13: mismatched input '.'.*");
    assertThat(statement("SELECT A.*")).ignoringLocation().isEqualTo(simpleQuery(new Select(false, ImmutableList.of(new AllColumns(new Identifier("A"), ImmutableList.of())))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Select(io.trino.sql.tree.Select) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Example 27 with Identifier

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

the class TestSqlParser method testNullTreatment.

@Test
public void testNullTreatment() {
    assertExpression("lead(x, 1) ignore nulls over()", new FunctionCall(Optional.empty(), QualifiedName.of("lead"), Optional.of(new WindowSpecification(Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty())), Optional.empty(), Optional.empty(), false, Optional.of(NullTreatment.IGNORE), Optional.empty(), ImmutableList.of(new Identifier("x"), new LongLiteral("1"))));
    assertExpression("lead(x, 1) respect nulls over()", new FunctionCall(Optional.empty(), QualifiedName.of("lead"), Optional.of(new WindowSpecification(Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty())), Optional.empty(), Optional.empty(), false, Optional.of(NullTreatment.RESPECT), Optional.empty(), ImmutableList.of(new Identifier("x"), new LongLiteral("1"))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) LongLiteral(io.trino.sql.tree.LongLiteral) WindowSpecification(io.trino.sql.tree.WindowSpecification) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.junit.jupiter.api.Test)

Example 28 with Identifier

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

the class TestSqlParser method testNonReserved.

@Test
public void testNonReserved() {
    assertStatement("SELECT zone FROM t", simpleQuery(selectList(new Identifier("zone")), table(QualifiedName.of("t"))));
    assertStatement("SELECT INCLUDING, EXCLUDING, PROPERTIES FROM t", simpleQuery(selectList(new Identifier("INCLUDING"), new Identifier("EXCLUDING"), new Identifier("PROPERTIES")), table(QualifiedName.of("t"))));
    assertStatement("SELECT ALL, SOME, ANY FROM t", simpleQuery(selectList(new Identifier("ALL"), new Identifier("SOME"), new Identifier("ANY")), table(QualifiedName.of("t"))));
    assertExpression("stats", new Identifier("stats"));
    assertExpression("nfd", new Identifier("nfd"));
    assertExpression("nfc", new Identifier("nfc"));
    assertExpression("nfkd", new Identifier("nfkd"));
    assertExpression("nfkc", new Identifier("nfkc"));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) Test(org.junit.jupiter.api.Test)

Example 29 with Identifier

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

the class TestSqlParser method testGrantRoles.

@Test
public void testGrantRoles() {
    assertStatement("GRANT role1 TO user1", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.empty()));
    assertStatement("GRANT role1, role2, role3 TO user1, USER user2, ROLE role4 WITH ADMIN OPTION", new GrantRoles(ImmutableSet.of(new Identifier("role1"), new Identifier("role2"), new Identifier("role3")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1")), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user2")), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role4"))), true, Optional.empty(), Optional.empty()));
    assertStatement("GRANT role1 TO user1 WITH ADMIN OPTION GRANTED BY admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO USER user1 WITH ADMIN OPTION GRANTED BY USER admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO ROLE role2 WITH ADMIN OPTION GRANTED BY ROLE admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO ROLE role2 GRANTED BY ROLE admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT \"role1\" TO ROLE \"role2\" GRANTED BY ROLE \"admin\"", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO user1 IN my_catalog", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.of(new Identifier("my_catalog"))));
}
Also used : GrantRoles(io.trino.sql.tree.GrantRoles) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) GrantorSpecification(io.trino.sql.tree.GrantorSpecification) Test(org.junit.jupiter.api.Test)

Example 30 with Identifier

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

the class TestSqlParser method testShowRoles.

@Test
public void testShowRoles() {
    assertStatement("SHOW ROLES", new ShowRoles(Optional.empty(), false));
    assertStatement("SHOW ROLES FROM foo", new ShowRoles(Optional.of(new Identifier("foo")), false));
    assertStatement("SHOW ROLES IN foo", new ShowRoles(Optional.of(new Identifier("foo")), false));
    assertStatement("SHOW CURRENT ROLES", new ShowRoles(Optional.empty(), true));
    assertStatement("SHOW CURRENT ROLES FROM foo", new ShowRoles(Optional.of(new Identifier("foo")), true));
    assertStatement("SHOW CURRENT ROLES IN foo", new ShowRoles(Optional.of(new Identifier("foo")), true));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) ShowRoles(io.trino.sql.tree.ShowRoles) Test(org.junit.jupiter.api.Test)

Aggregations

Identifier (io.trino.sql.tree.Identifier)71 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)37 Test (org.junit.jupiter.api.Test)37 FunctionCall (io.trino.sql.tree.FunctionCall)19 StringLiteral (io.trino.sql.tree.StringLiteral)19 LongLiteral (io.trino.sql.tree.LongLiteral)18 Test (org.testng.annotations.Test)15 CreateTable (io.trino.sql.tree.CreateTable)14 Property (io.trino.sql.tree.Property)14 Expression (io.trino.sql.tree.Expression)13 Table (io.trino.sql.tree.Table)12 DropTable (io.trino.sql.tree.DropTable)11 AllColumns (io.trino.sql.tree.AllColumns)9 QualifiedName (io.trino.sql.tree.QualifiedName)9 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)8 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)6 Session (io.trino.Session)6 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)6 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)5