use of io.hetu.core.spi.cube.io.CubeMetaStore in project hetu-core by openlookeng.
the class DropColumnTask method execute.
@Override
public ListenableFuture<?> execute(DropColumn 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 column = statement.getColumn().getValue().toLowerCase(ENGLISH);
accessControl.checkCanDropColumn(session.getRequiredTransactionId(), session.getIdentity(), tableName);
ColumnHandle columnHandle = metadata.getColumnHandles(session, tableHandle).get(column);
if (columnHandle == null) {
throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", column);
}
if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {
throw new SemanticException(NOT_SUPPORTED, statement, "Cannot drop hidden column");
}
if (metadata.getTableMetadata(session, tableHandle).getColumns().stream().filter(info -> !info.isHidden()).count() <= 1) {
throw new SemanticException(NOT_SUPPORTED, statement, "Cannot drop the only column in a table");
}
metadata.dropColumn(session, tableHandle, columnHandle);
return immediateFuture(null);
}
use of io.hetu.core.spi.cube.io.CubeMetaStore 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.hetu.core.spi.cube.io.CubeMetaStore 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.hetu.core.spi.cube.io.CubeMetaStore in project hetu-core by openlookeng.
the class RenameTableTask method execute.
@Override
public ListenableFuture<?> execute(RenameTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
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);
}
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
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(), tableName, target);
metadata.renameTable(session, tableHandle.get(), target);
return immediateFuture(null);
}
use of io.hetu.core.spi.cube.io.CubeMetaStore 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());
}
}
Aggregations