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