use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.
the class TestSqlParser method testCreateRole.
@Test
public void testCreateRole() {
assertStatement("CREATE ROLE role", new CreateRole(new Identifier("role"), Optional.empty(), Optional.empty()));
assertStatement("CREATE ROLE role1 WITH ADMIN admin", new CreateRole(new Identifier("role1"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin"))))), Optional.empty()));
assertStatement("CREATE ROLE \"role\" WITH ADMIN \"admin\"", new CreateRole(new Identifier("role"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin"))))), Optional.empty()));
assertStatement("CREATE ROLE \"ro le\" WITH ADMIN \"ad min\"", new CreateRole(new Identifier("ro le"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("ad min"))))), Optional.empty()));
assertStatement("CREATE ROLE \"!@#$%^&*'\" WITH ADMIN \"ад\"\"мін\"", new CreateRole(new Identifier("!@#$%^&*'"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("ад\"мін"))))), Optional.empty()));
assertStatement("CREATE ROLE role2 WITH ADMIN USER admin1", new CreateRole(new Identifier("role2"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("admin1"))))), Optional.empty()));
assertStatement("CREATE ROLE role2 WITH ADMIN ROLE role1", new CreateRole(new Identifier("role2"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role1"))))), Optional.empty()));
assertStatement("CREATE ROLE role2 WITH ADMIN CURRENT_USER", new CreateRole(new Identifier("role2"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.CURRENT_USER, Optional.empty())), Optional.empty()));
assertStatement("CREATE ROLE role2 WITH ADMIN CURRENT_ROLE", new CreateRole(new Identifier("role2"), Optional.of(new GrantorSpecification(GrantorSpecification.Type.CURRENT_ROLE, Optional.empty())), Optional.empty()));
assertStatement("CREATE ROLE role IN my_catalog", new CreateRole(new Identifier("role"), Optional.empty(), Optional.of(new Identifier("my_catalog"))));
}
use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.
the class TestSqlParser method testDeny.
@Test
public void testDeny() {
assertStatement("DENY INSERT, DELETE ON t TO u", new Deny(Optional.of(ImmutableList.of("INSERT", "DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u"))));
assertStatement("DENY UPDATE ON t TO u", new Deny(Optional.of(ImmutableList.of("UPDATE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u"))));
assertStatement("DENY ALL PRIVILEGES ON TABLE t TO USER u", new Deny(Optional.empty(), Optional.of(GrantOnType.TABLE), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u"))));
assertStatement("DENY SELECT ON SCHEMA s TO USER u", new Deny(Optional.of(ImmutableList.of("SELECT")), Optional.of(GrantOnType.SCHEMA), QualifiedName.of("s"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u"))));
}
use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.
the class TestSqlParser method testAlterViewSetAuthorization.
@Test
public void testAlterViewSetAuthorization() {
assertStatement("ALTER VIEW foo.bar.baz SET AUTHORIZATION qux", new SetViewAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("qux"))));
assertStatement("ALTER VIEW foo.bar.baz SET AUTHORIZATION USER qux", new SetViewAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("qux"))));
assertStatement("ALTER VIEW foo.bar.baz SET AUTHORIZATION ROLE qux", new SetViewAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("qux"))));
}
Aggregations