Search in sources :

Example 1 with SetTableAuthorization

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

the class SetTableAuthorizationTask method execute.

@Override
public ListenableFuture<Void> execute(SetTableAuthorization statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
    getRequiredCatalogHandle(metadata, session, statement, tableName.getCatalogName());
    if (metadata.getTableHandle(session, tableName).isEmpty()) {
        throw semanticException(TABLE_NOT_FOUND, statement, "Table '%s' does not exist", tableName);
    }
    TrinoPrincipal principal = createPrincipal(statement.getPrincipal());
    checkRoleExists(session, statement, metadata, principal, Optional.of(tableName.getCatalogName()).filter(catalog -> metadata.isCatalogManagedSecurity(session, catalog)));
    accessControl.checkCanSetTableAuthorization(session.toSecurityContext(), tableName, principal);
    metadata.setTableAuthorization(session, tableName.asCatalogSchemaTableName(), principal);
    return immediateVoidFuture();
}
Also used : Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MetadataUtil.checkRoleExists(io.trino.metadata.MetadataUtil.checkRoleExists) MetadataUtil.getRequiredCatalogHandle(io.trino.metadata.MetadataUtil.getRequiredCatalogHandle) Inject(javax.inject.Inject) List(java.util.List) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AccessControl(io.trino.security.AccessControl) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) MetadataUtil.createPrincipal(io.trino.metadata.MetadataUtil.createPrincipal) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) TABLE_NOT_FOUND(io.trino.spi.StandardErrorCode.TABLE_NOT_FOUND) Objects.requireNonNull(java.util.Objects.requireNonNull) WarningCollector(io.trino.execution.warnings.WarningCollector) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) SetTableAuthorization(io.trino.sql.tree.SetTableAuthorization) SemanticExceptions.semanticException(io.trino.sql.analyzer.SemanticExceptions.semanticException) Session(io.trino.Session) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) Session(io.trino.Session)

Example 2 with SetTableAuthorization

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

the class TestSqlParser method testAlterTableSetAuthorization.

@Test
public void testAlterTableSetAuthorization() {
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("qux"))));
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION USER qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("qux"))));
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION ROLE qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("qux"))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) SetTableAuthorization(io.trino.sql.tree.SetTableAuthorization) Test(org.junit.jupiter.api.Test)

Aggregations

SetTableAuthorization (io.trino.sql.tree.SetTableAuthorization)2 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Session (io.trino.Session)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 Metadata (io.trino.metadata.Metadata)1 MetadataUtil.checkRoleExists (io.trino.metadata.MetadataUtil.checkRoleExists)1 MetadataUtil.createPrincipal (io.trino.metadata.MetadataUtil.createPrincipal)1 MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)1 MetadataUtil.getRequiredCatalogHandle (io.trino.metadata.MetadataUtil.getRequiredCatalogHandle)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 AccessControl (io.trino.security.AccessControl)1 TABLE_NOT_FOUND (io.trino.spi.StandardErrorCode.TABLE_NOT_FOUND)1 TrinoPrincipal (io.trino.spi.security.TrinoPrincipal)1 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)1 SemanticExceptions.semanticException (io.trino.sql.analyzer.SemanticExceptions.semanticException)1 Expression (io.trino.sql.tree.Expression)1 Identifier (io.trino.sql.tree.Identifier)1 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)1 List (java.util.List)1