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