Search in sources :

Example 26 with SemanticException

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());
    }
}
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)

Example 27 with SemanticException

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);
}
Also used : IndexClient(io.prestosql.spi.heuristicindex.IndexClient) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IndexRecord(io.prestosql.spi.heuristicindex.IndexRecord) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SemanticException(io.prestosql.sql.analyzer.SemanticException) Session(io.prestosql.Session)

Example 28 with SemanticException

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

Example 29 with SemanticException

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

Example 30 with SemanticException

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