use of com.facebook.presto.spi.CatalogSchemaName in project presto by prestodb.
the class DropSchemaTask method execute.
@Override
public ListenableFuture<?> execute(DropSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
if (statement.isCascade()) {
throw new PrestoException(NOT_SUPPORTED, "CASCADE is not yet supported for DROP SCHEMA");
}
Session session = stateMachine.getSession();
CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
if (!metadata.schemaExists(session, schema)) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", schema);
}
return immediateFuture(null);
}
accessControl.checkCanDropSchema(session.getRequiredTransactionId(), session.getIdentity(), schema);
metadata.dropSchema(session, schema);
return immediateFuture(null);
}
use of com.facebook.presto.spi.CatalogSchemaName in project presto by prestodb.
the class RenameSchemaTask method execute.
@Override
public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget());
if (!metadata.schemaExists(session, source)) {
throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", source);
}
if (metadata.schemaExists(session, target)) {
throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target);
}
accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), source, statement.getTarget());
metadata.renameSchema(session, source, statement.getTarget());
return immediateFuture(null);
}
use of com.facebook.presto.spi.CatalogSchemaName in project presto by prestodb.
the class CreateSchemaTask method execute.
@Override
public ListenableFuture<?> execute(CreateSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
// TODO: validate that catalog exists
accessControl.checkCanCreateSchema(session.getRequiredTransactionId(), session.getIdentity(), schema);
if (metadata.schemaExists(session, schema)) {
if (!statement.isNotExists()) {
throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Schema '%s' already exists", schema);
}
return immediateFuture(null);
}
ConnectorId connectorId = metadata.getCatalogHandle(session, schema.getCatalogName()).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + schema.getCatalogName()));
Map<String, Object> properties = metadata.getSchemaPropertyManager().getProperties(connectorId, schema.getCatalogName(), statement.getProperties(), session, metadata, parameters);
metadata.createSchema(session, schema, properties);
return immediateFuture(null);
}
use of com.facebook.presto.spi.CatalogSchemaName in project presto by prestodb.
the class TestAccessControlManager method testReadOnlySystemAccessControl.
@Test
public void testReadOnlySystemAccessControl() throws Exception {
Identity identity = new Identity(USER_NAME, Optional.of(PRINCIPAL));
QualifiedObjectName tableName = new QualifiedObjectName("catalog", "schema", "table");
TransactionManager transactionManager = createTestTransactionManager();
AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
accessControlManager.setSystemAccessControl(ReadOnlySystemAccessControl.NAME, ImmutableMap.of());
accessControlManager.checkCanSetUser(PRINCIPAL, USER_NAME);
accessControlManager.checkCanSetSystemSessionProperty(identity, "property");
transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanSetCatalogSessionProperty(transactionId, identity, "catalog", "property");
accessControlManager.checkCanSelectFromTable(transactionId, identity, tableName);
accessControlManager.checkCanSelectFromView(transactionId, identity, tableName);
accessControlManager.checkCanCreateViewWithSelectFromTable(transactionId, identity, tableName);
accessControlManager.checkCanCreateViewWithSelectFromView(transactionId, identity, tableName);
accessControlManager.checkCanShowSchemas(transactionId, identity, "catalog");
accessControlManager.checkCanShowTables(transactionId, identity, new CatalogSchemaName("catalog", "schema"));
Set<String> catalogs = ImmutableSet.of("catalog");
assertEquals(accessControlManager.filterCatalogs(identity, catalogs), catalogs);
Set<String> schemas = ImmutableSet.of("schema");
assertEquals(accessControlManager.filterSchemas(transactionId, identity, "catalog", schemas), schemas);
Set<SchemaTableName> tableNames = ImmutableSet.of(new SchemaTableName("schema", "table"));
assertEquals(accessControlManager.filterTables(transactionId, identity, "catalog", tableNames), tableNames);
});
try {
transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanInsertIntoTable(transactionId, identity, tableName);
});
fail();
} catch (AccessDeniedException expected) {
}
}
Aggregations