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())))));
}
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"))));
}
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"));
}
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"))));
}
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));
}
Aggregations