use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropCubeTask method execute.
@Override
public ListenableFuture<?> execute(DropCube statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
Optional<CubeMetaStore> optionalCubeMetaStore = this.cubeManager.getMetaStore(STAR_TREE);
if (!optionalCubeMetaStore.isPresent()) {
throw new RuntimeException("HetuMetastore is not initialized");
}
CubeMetaStore cubeMetaStore = optionalCubeMetaStore.get();
QualifiedObjectName fullObjectName = createQualifiedObjectName(session, statement, statement.getCubeName());
QualifiedName cubeTableName = QualifiedName.of(fullObjectName.getCatalogName(), fullObjectName.getSchemaName(), fullObjectName.getObjectName());
try {
Optional<CubeMetadata> matchedCube = cubeMetaStore.getMetadataFromCubeName(cubeTableName.toString());
if (!matchedCube.isPresent()) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_CUBE, statement, "Cube '%s' does not exist", cubeTableName);
}
return immediateFuture(null);
}
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, fullObjectName);
tableHandle.ifPresent(handle -> {
accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), fullObjectName);
metadata.dropTable(session, handle);
});
cubeMetaStore.removeCube(matchedCube.get());
return immediateFuture(null);
} catch (TableNotFoundException s) {
throw new SemanticException(MISSING_CUBE, statement, "Cube '%s' is not Found", cubeTableName.toString());
}
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropIndexTask method execute.
@Override
public ListenableFuture<?> execute(DropIndex statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
IndexClient indexClient = heuristicIndexerManager.getIndexClient();
String indexName = statement.getIndexName().toString();
try {
IndexRecord record = indexClient.lookUpIndexRecord(indexName);
// check indexName exist, call heuristic index api to drop index
if (record == null) {
throw new SemanticException(MISSING_INDEX, statement, "Index '%s' does not exist", indexName);
}
QualifiedObjectName fullObjectName = QualifiedObjectName.valueOf(record.qualifiedTable);
Session session = stateMachine.getSession();
accessControl.checkCanDropIndex(session.getRequiredTransactionId(), session.getIdentity(), fullObjectName);
List<String> partitions = Collections.emptyList();
if (statement.getPartitions().isPresent()) {
partitions = HeuristicIndexUtils.extractPartitions(statement.getPartitions().get());
List<String> partitionsInindex = indexClient.lookUpIndexRecord(indexName).partitions;
if (partitionsInindex.isEmpty()) {
throw new SemanticException(MISSING_INDEX, statement, "Index '%s' was not created with explicit partitions. Partial drop by partition is not supported.", indexName);
}
List<String> missingPartitions = new ArrayList<>(partitions);
missingPartitions.removeAll(partitionsInindex);
if (!missingPartitions.isEmpty()) {
throw new SemanticException(MISSING_INDEX, statement, "Index '%s' does not contain partitions: %s", indexName, missingPartitions);
}
}
indexClient.deleteIndex(indexName, partitions);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class DropSchemaTask method execute.
@Override
public ListenableFuture<?> execute(DropSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
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);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class CreateRoleTask method execute.
@Override
public ListenableFuture<?> execute(CreateRole 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();
Optional<PrestoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
accessControl.checkCanCreateRole(session.getRequiredTransactionId(), session.getIdentity(), role, grantor, catalog);
Set<String> existingRoles = metadata.listRoles(session, catalog);
if (existingRoles.contains(role)) {
throw new SemanticException(ROLE_ALREADY_EXIST, statement, "Role '%s' already exists", role);
}
if (grantor.isPresent() && grantor.get().getType() == ROLE && !existingRoles.contains(grantor.get().getName())) {
throw new SemanticException(MISSING_ROLE, statement, "Role '%s' does not exist", grantor.get().getName());
}
metadata.createRole(session, role, grantor, catalog);
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class CreateSchemaTask method execute.
@Override
public ListenableFuture<?> execute(CreateSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
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);
}
CatalogName catalogName = metadata.getCatalogHandle(session, schema.getCatalogName()).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + schema.getCatalogName()));
Map<String, Object> properties = metadata.getSchemaPropertyManager().getProperties(catalogName, schema.getCatalogName(), mapFromProperties(statement.getProperties()), session, metadata, parameters);
metadata.createSchema(session, schema, properties);
return immediateFuture(null);
}
Aggregations