Search in sources :

Example 16 with SemanticException

use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.

the class RevokeTask method execute.

@Override
public ListenableFuture<?> execute(Revoke statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }
    Set<Privilege> privileges;
    if (statement.getPrivileges().isPresent()) {
        privileges = statement.getPrivileges().get().stream().map(privilege -> parsePrivilege(statement, privilege)).collect(toImmutableSet());
    } else {
        // All privileges
        privileges = EnumSet.allOf(Privilege.class);
    }
    // verify current identity has permissions to revoke permissions
    for (Privilege privilege : privileges) {
        accessControl.checkCanRevokeTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), privilege, tableName, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
    }
    metadata.revokeTablePrivileges(session, tableName, privileges, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
    return immediateFuture(null);
}
Also used : TableHandle(com.facebook.presto.spi.TableHandle) Privilege(com.facebook.presto.spi.security.Privilege) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 17 with SemanticException

use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.

the class GrantTask method execute.

@Override
public ListenableFuture<?> execute(Grant statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }
    Set<Privilege> privileges;
    if (statement.getPrivileges().isPresent()) {
        privileges = statement.getPrivileges().get().stream().map(privilege -> parsePrivilege(statement, privilege)).collect(toImmutableSet());
    } else {
        // All privileges
        privileges = EnumSet.allOf(Privilege.class);
    }
    // verify current identity has permissions to grant permissions
    for (Privilege privilege : privileges) {
        accessControl.checkCanGrantTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), privilege, tableName, createPrincipal(statement.getGrantee()), statement.isWithGrantOption());
    }
    metadata.grantTablePrivileges(session, tableName, privileges, createPrincipal(statement.getGrantee()), statement.isWithGrantOption());
    return immediateFuture(null);
}
Also used : TableHandle(com.facebook.presto.spi.TableHandle) Privilege(com.facebook.presto.spi.security.Privilege) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 18 with SemanticException

use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.

the class DropMaterializedViewTask method execute.

@Override
public ListenableFuture<?> execute(DropMaterializedView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
    Optional<ConnectorMaterializedViewDefinition> view = metadata.getMaterializedView(session, name);
    if (!view.isPresent()) {
        if (!statement.isExists()) {
            throw new SemanticException(MISSING_MATERIALIZED_VIEW, statement, "Materialized view '%s' does not exist", name);
        }
        return immediateFuture(null);
    }
    accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), name);
    accessControl.checkCanDropView(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), name);
    metadata.dropMaterializedView(session, name);
    return immediateFuture(null);
}
Also used : ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 19 with SemanticException

use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.

the class TestQueryPreparer method testTooManyParameters.

@Test
public void testTooManyParameters() {
    try {
        Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo where col1 = ?").build();
        QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1,2", WarningCollector.NOOP);
        fail("expected exception");
    } catch (SemanticException e) {
        assertEquals(e.getCode(), INVALID_PARAMETER_USAGE);
    }
}
Also used : Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 20 with SemanticException

use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.

the class TestQueryPreparer method testTooFewParameters.

@Test
public void testTooFewParameters() {
    try {
        Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT ? FROM foo where col1 = ?").build();
        QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1", WarningCollector.NOOP);
        fail("expected exception");
    } catch (SemanticException e) {
        assertEquals(e.getCode(), INVALID_PARAMETER_USAGE);
    }
}
Also used : Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Aggregations

SemanticException (com.facebook.presto.sql.analyzer.SemanticException)45 Session (com.facebook.presto.Session)29 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)21 PrestoException (com.facebook.presto.spi.PrestoException)14 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)12 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)9 TableHandle (com.facebook.presto.spi.TableHandle)9 Test (org.testng.annotations.Test)9 Expression (com.facebook.presto.sql.tree.Expression)8 TableHandle (com.facebook.presto.metadata.TableHandle)7 ConnectorId (com.facebook.presto.spi.ConnectorId)7 ConnectorMaterializedViewDefinition (com.facebook.presto.spi.ConnectorMaterializedViewDefinition)7 MetadataUtil.createCatalogSchemaName (com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName)6 TransactionManager (com.facebook.presto.transaction.TransactionManager)6 ColumnHandle (com.facebook.presto.spi.ColumnHandle)5 Type (com.facebook.presto.common.type.Type)4 Metadata (com.facebook.presto.metadata.Metadata)4 AccessControl (com.facebook.presto.security.AccessControl)4 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 Privilege (com.facebook.presto.spi.security.Privilege)4