use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropRoleTask method execute.
@Override
public ListenableFuture<?> execute(DropRole statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
String catalog = createCatalogName(session, statement);
String role = statement.getName().getValue();
accessControl.checkCanDropRole(session.getRequiredTransactionId(), session.getIdentity(), role, catalog);
Set<String> existingRoles = metadata.listRoles(session, catalog);
if (!existingRoles.contains(role)) {
throw new SemanticException(MISSING_ROLE, statement, "Role '%s' does not exist", role);
}
metadata.dropRole(session, role, catalog);
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropTableTask method execute.
@Override
public ListenableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName fullObjectName = createQualifiedObjectName(session, statement, statement.getTableName());
QualifiedName tableName = QualifiedName.of(fullObjectName.getCatalogName(), fullObjectName.getSchemaName(), fullObjectName.getObjectName());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, fullObjectName);
if (!tableHandle.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
return immediateFuture(null);
}
Optional<CubeMetaStore> optionalCubeMetaStore = this.cubeManager.getMetaStore(STAR_TREE);
if (optionalCubeMetaStore.isPresent() && optionalCubeMetaStore.get().getMetadataFromCubeName(tableName.toString()).isPresent()) {
throw new SemanticException(DROP_TABLE_ON_CUBE, statement, "%s is a star-tree cube, drop using DROP CUBE", tableName);
}
accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), fullObjectName);
if (PropertyService.getBooleanProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED)) {
// Check if SplitCacheMap is enabled
SplitCacheMap splitCacheMap = SplitCacheMap.getInstance();
if (splitCacheMap.cacheExists(tableName)) {
splitCacheMap.dropCache(tableName, Optional.empty());
}
}
metadata.dropTable(session, tableHandle.get());
if (optionalCubeMetaStore.isPresent()) {
List<CubeMetadata> cubes = optionalCubeMetaStore.get().getMetadataList(tableName.toString());
for (CubeMetadata cube : cubes) {
String[] parts = cube.getCubeName().split("\\.");
Optional<TableHandle> cubeHandle = metadata.getTableHandle(session, createQualifiedObjectName(session, null, QualifiedName.of(parts[0], parts[1], parts[2])));
try {
cubeHandle.ifPresent(cubeTable -> metadata.dropTable(session, cubeTable));
optionalCubeMetaStore.get().removeCube(cube);
} catch (TableNotFoundException e) {
// Can happen in concurrent drop table and drop cube calls
LOG.debug("Tried dropping cube table but it is already dropped", e);
}
}
}
dropIndices(heuristicIndexerManager, tableName);
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropViewTask method execute.
@Override
public ListenableFuture<?> execute(DropView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
Optional<ConnectorViewDefinition> view = metadata.getView(session, name);
if (!view.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_TABLE, statement, "View '%s' does not exist", name);
}
return immediateFuture(null);
}
accessControl.checkCanDropView(session.getRequiredTransactionId(), session.getIdentity(), name);
metadata.dropView(session, name);
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class RenameColumnTask method execute.
@Override
public ListenableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
Optional<CubeMetaStore> optionalCubeMetaStore = this.cubeManager.getMetaStore(STAR_TREE);
if (optionalCubeMetaStore.isPresent() && optionalCubeMetaStore.get().getMetadataFromCubeName(tableName.toString()).isPresent()) {
throw new SemanticException(ALTER_TABLE_ON_CUBE, statement, "Operation not permitted. %s is a Cube table, use CUBE statements instead.", tableName);
}
TableHandle tableHandle = metadata.getTableHandle(session, tableName).orElseThrow(() -> new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName));
String source = statement.getSource().getValue().toLowerCase(ENGLISH);
String target = statement.getTarget().getValue().toLowerCase(ENGLISH);
accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), tableName);
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
ColumnHandle columnHandle = columnHandles.get(source);
if (columnHandle == null) {
throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
}
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 io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class RenameSchemaTask method execute.
@Override
public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget().getValue());
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().getValue());
metadata.renameSchema(session, source, statement.getTarget().getValue());
return immediateFuture(null);
}
Aggregations