Search in sources :

Example 11 with SemanticException

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);
}
Also used : Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 12 with SemanticException

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);
}
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 13 with SemanticException

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

Example 14 with SemanticException

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);
}
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 15 with SemanticException

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);
}
Also used : MetadataUtil.createCatalogSchemaName(io.prestosql.metadata.MetadataUtil.createCatalogSchemaName) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Aggregations

SemanticException (io.prestosql.sql.analyzer.SemanticException)34 Session (io.prestosql.Session)27 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)16 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)14 PrestoException (io.prestosql.spi.PrestoException)13 TableHandle (io.prestosql.spi.metadata.TableHandle)11 Expression (io.prestosql.sql.tree.Expression)8 CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)7 CatalogName (io.prestosql.spi.connector.CatalogName)7 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)6 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Metadata (io.prestosql.metadata.Metadata)5 AccessControl (io.prestosql.security.AccessControl)5 Type (io.prestosql.spi.type.Type)5 TransactionManager (io.prestosql.transaction.TransactionManager)5 List (java.util.List)5 Map (java.util.Map)4 Optional (java.util.Optional)4 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)3