Search in sources :

Example 6 with CubeMetaStore

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);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 7 with CubeMetaStore

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);
}
Also used : QualifiedName(io.prestosql.sql.tree.QualifiedName) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) TableHandle(io.prestosql.spi.metadata.TableHandle) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 8 with CubeMetaStore

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);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 9 with CubeMetaStore

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);
}
Also used : CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TableHandle(io.prestosql.spi.metadata.TableHandle) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 10 with CubeMetaStore

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());
    }
}
Also used : TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) QualifiedName(io.prestosql.sql.tree.QualifiedName) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TableHandle(io.prestosql.spi.metadata.TableHandle) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Aggregations

CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)13 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)12 TableHandle (io.prestosql.spi.metadata.TableHandle)12 Session (io.prestosql.Session)11 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)8 CubeMetadata (io.hetu.core.spi.cube.CubeMetadata)7 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)7 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)7 SemanticException (io.prestosql.sql.analyzer.SemanticException)7 CubeManager (io.prestosql.cube.CubeManager)6 TableMetadata (io.prestosql.metadata.TableMetadata)6 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)6 CubeProvider (io.prestosql.spi.cube.CubeProvider)6 QualifiedName (io.prestosql.sql.tree.QualifiedName)6 ImmutableList (com.google.common.collect.ImmutableList)5 Metadata (io.prestosql.metadata.Metadata)5 TpchColumnHandle (io.prestosql.plugin.tpch.TpchColumnHandle)5 TpchTableHandle (io.prestosql.plugin.tpch.TpchTableHandle)5 TpchTableLayoutHandle (io.prestosql.plugin.tpch.TpchTableLayoutHandle)5 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)5