use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestMinimalFunctionality method testTopicExists.
@Test
public void testTopicExists() {
QualifiedObjectName name = new QualifiedObjectName("kafka", "default", topicName);
transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
assertTrue(handle.isPresent());
});
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class SqlQueryExecution method extractConnectors.
private static Set<ConnectorId> extractConnectors(Analysis analysis) {
ImmutableSet.Builder<ConnectorId> connectors = ImmutableSet.builder();
for (TableHandle tableHandle : analysis.getTables()) {
connectors.add(tableHandle.getConnectorId());
}
if (analysis.getInsert().isPresent()) {
TableHandle target = analysis.getInsert().get().getTarget();
connectors.add(target.getConnectorId());
}
return connectors.build();
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class RenameColumnTask method execute.
@Override
public ListenableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
Optional<TableHandle> tableHandleOptional = metadata.getTableHandle(session, tableName);
if (!tableHandleOptional.isPresent()) {
if (!statement.isTableExists()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
return immediateFuture(null);
}
Optional<ConnectorMaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, tableName);
if (optionalMaterializedView.isPresent()) {
if (!statement.isTableExists()) {
throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and rename column is not supported", tableName);
}
return immediateFuture(null);
}
TableHandle tableHandle = tableHandleOptional.get();
String source = statement.getSource().getValue().toLowerCase(ENGLISH);
String target = statement.getTarget().getValue().toLowerCase(ENGLISH);
accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
ColumnHandle columnHandle = columnHandles.get(source);
if (columnHandle == null) {
if (!statement.isColumnExists()) {
throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
}
return immediateFuture(null);
}
if (columnHandles.containsKey(target)) {
throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
}
if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {
throw new SemanticException(NOT_SUPPORTED, statement, "Cannot rename hidden column");
}
metadata.renameColumn(session, tableHandle, columnHandle, target);
return immediateFuture(null);
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class RenameTableTask method execute.
@Override
public ListenableFuture<?> execute(RenameTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
return immediateFuture(null);
}
Optional<ConnectorMaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, tableName);
if (optionalMaterializedView.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and rename is not supported", tableName);
}
return immediateFuture(null);
}
QualifiedObjectName target = createQualifiedObjectName(session, statement, statement.getTarget());
if (!metadata.getCatalogHandle(session, target.getCatalogName()).isPresent()) {
throw new SemanticException(MISSING_CATALOG, statement, "Target catalog '%s' does not exist", target.getCatalogName());
}
if (metadata.getTableHandle(session, target).isPresent()) {
throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Target table '%s' already exists", target);
}
if (!tableName.getCatalogName().equals(target.getCatalogName())) {
throw new SemanticException(NOT_SUPPORTED, statement, "Table rename across catalogs is not supported");
}
accessControl.checkCanRenameTable(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName, target);
metadata.renameTable(session, tableHandle.get(), target);
return immediateFuture(null);
}
use of com.facebook.presto.spi.TableHandle 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);
}
Aggregations