Search in sources :

Example 1 with MISSING_CATALOG_NAME

use of io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME in project trino by trinodb.

the class UseTask method execute.

@Override
public ListenableFuture<Void> execute(Use statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    String catalog = statement.getCatalog().map(identifier -> identifier.getValue().toLowerCase(ENGLISH)).orElseGet(() -> session.getCatalog().orElseThrow(() -> semanticException(MISSING_CATALOG_NAME, statement, "Catalog must be specified when session catalog is not set")));
    if (metadata.getCatalogHandle(session, catalog).isEmpty()) {
        throw new TrinoException(NOT_FOUND, "Catalog does not exist: " + catalog);
    }
    String schema = statement.getSchema().getValue().toLowerCase(ENGLISH);
    CatalogSchemaName name = new CatalogSchemaName(catalog, schema);
    if (!metadata.schemaExists(session, name)) {
        throw new TrinoException(NOT_FOUND, "Schema does not exist: " + name);
    }
    if (statement.getCatalog().isPresent()) {
        stateMachine.setSetCatalog(catalog);
    }
    stateMachine.setSetSchema(schema);
    return immediateVoidFuture();
}
Also used : NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TrinoException(io.trino.spi.TrinoException) MISSING_CATALOG_NAME(io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME) Use(io.trino.sql.tree.Use) Inject(javax.inject.Inject) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) WarningCollector(io.trino.execution.warnings.WarningCollector) CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) Metadata(io.trino.metadata.Metadata) Expression(io.trino.sql.tree.Expression) SemanticExceptions.semanticException(io.trino.sql.analyzer.SemanticExceptions.semanticException) ENGLISH(java.util.Locale.ENGLISH) Session(io.trino.Session) CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session)

Aggregations

Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Session (io.trino.Session)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 Metadata (io.trino.metadata.Metadata)1 MISSING_CATALOG_NAME (io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME)1 NOT_FOUND (io.trino.spi.StandardErrorCode.NOT_FOUND)1 TrinoException (io.trino.spi.TrinoException)1 CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)1 SemanticExceptions.semanticException (io.trino.sql.analyzer.SemanticExceptions.semanticException)1 Expression (io.trino.sql.tree.Expression)1 Use (io.trino.sql.tree.Use)1 List (java.util.List)1 ENGLISH (java.util.Locale.ENGLISH)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Inject (javax.inject.Inject)1