Search in sources :

Example 6 with PrincipalSpecification

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"))));
}
Also used : 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) CreateRole(io.trino.sql.tree.CreateRole) Test(org.junit.jupiter.api.Test)

Example 7 with PrincipalSpecification

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"))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) Deny(io.trino.sql.tree.Deny) Test(org.junit.jupiter.api.Test)

Example 8 with PrincipalSpecification

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"))));
}
Also used : SetViewAuthorization(io.trino.sql.tree.SetViewAuthorization) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) Test(org.junit.jupiter.api.Test)

Aggregations

QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)8 Identifier (io.trino.sql.tree.Identifier)8 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)8 Test (org.junit.jupiter.api.Test)8 GrantorSpecification (io.trino.sql.tree.GrantorSpecification)3 CreateRole (io.trino.sql.tree.CreateRole)1 Deny (io.trino.sql.tree.Deny)1 Grant (io.trino.sql.tree.Grant)1 GrantRoles (io.trino.sql.tree.GrantRoles)1 Revoke (io.trino.sql.tree.Revoke)1 RevokeRoles (io.trino.sql.tree.RevokeRoles)1 SetTableAuthorization (io.trino.sql.tree.SetTableAuthorization)1 SetViewAuthorization (io.trino.sql.tree.SetViewAuthorization)1