Search in sources :

Example 1 with CatalogSchemaName

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);
}
Also used : CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName) PrestoException(com.facebook.presto.spi.PrestoException) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 2 with CatalogSchemaName

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);
}
Also used : CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 3 with CatalogSchemaName

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);
}
Also used : CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName) PrestoException(com.facebook.presto.spi.PrestoException) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 4 with CatalogSchemaName

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) {
    }
}
Also used : AccessDeniedException(com.facebook.presto.spi.security.AccessDeniedException) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) Identity(com.facebook.presto.spi.security.Identity) SchemaTableName(com.facebook.presto.spi.SchemaTableName) CatalogSchemaTableName(com.facebook.presto.spi.CatalogSchemaTableName) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

CatalogSchemaName (com.facebook.presto.spi.CatalogSchemaName)4 Session (com.facebook.presto.Session)3 MetadataUtil.createCatalogSchemaName (com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName)3 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)3 PrestoException (com.facebook.presto.spi.PrestoException)2 ConnectorId (com.facebook.presto.connector.ConnectorId)1 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)1 CatalogSchemaTableName (com.facebook.presto.spi.CatalogSchemaTableName)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 AccessDeniedException (com.facebook.presto.spi.security.AccessDeniedException)1 Identity (com.facebook.presto.spi.security.Identity)1 TransactionManager (com.facebook.presto.transaction.TransactionManager)1 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)1 Test (org.testng.annotations.Test)1