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