Skip to content

Commit

Permalink
Use MISSING_CATALOG_NAME error code
Browse files Browse the repository at this point in the history
Previously IllegalArgumentException was translated to
GENERIC_INTERNAL_ERROR.
  • Loading branch information
losipiuk committed Sep 13, 2023
1 parent bd6a4dc commit 55089e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static io.trino.spi.StandardErrorCode.AMBIGUOUS_FUNCTION_CALL;
import static io.trino.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_MISSING;
import static io.trino.spi.StandardErrorCode.FUNCTION_NOT_FOUND;
import static io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME;
import static io.trino.spi.function.FunctionKind.AGGREGATE;
import static io.trino.spi.function.FunctionKind.SCALAR;
import static io.trino.spi.function.FunctionKind.WINDOW;
Expand Down Expand Up @@ -219,7 +220,7 @@ public static List<CatalogSchemaFunctionName> toPath(Session session, QualifiedF

if (name.getSchemaName().isPresent()) {
String currentCatalog = session.getCatalog()
.orElseThrow(() -> new IllegalArgumentException("Session default catalog must be set to resolve a partial function name: " + name));
.orElseThrow(() -> new TrinoException(MISSING_CATALOG_NAME, "Session default catalog must be set to resolve a partial function name: " + name));
return ImmutableList.of(new CatalogSchemaFunctionName(currentCatalog, name.getSchemaName().orElseThrow(), name.getFunctionName()));
}

Expand All @@ -231,7 +232,7 @@ public static List<CatalogSchemaFunctionName> toPath(Session session, QualifiedF
// add resolved path items
for (SqlPathElement sqlPathElement : session.getPath().getParsedPath()) {
String catalog = sqlPathElement.getCatalog().map(Identifier::getCanonicalValue).or(session::getCatalog)
.orElseThrow(() -> new IllegalArgumentException("Session default catalog must be set to resolve a partial function name: " + name));
.orElseThrow(() -> new TrinoException(MISSING_CATALOG_NAME, "Session default catalog must be set to resolve a partial function name: " + name));
names.add(new CatalogSchemaFunctionName(catalog, sqlPathElement.getSchema().getCanonicalValue(), name.getFunctionName()));
}
return names.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
import static io.trino.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_MISSING;
import static io.trino.spi.StandardErrorCode.FUNCTION_NOT_FOUND;
import static io.trino.spi.StandardErrorCode.INVALID_VIEW;
import static io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME;
import static io.trino.spi.StandardErrorCode.NOT_FOUND;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_FOUND;
Expand Down Expand Up @@ -2276,7 +2277,7 @@ public Collection<FunctionMetadata> listFunctions(Session session)
functions.addAll(this.functions.listFunctions());
for (SqlPathElement sqlPathElement : session.getPath().getParsedPath()) {
String catalog = sqlPathElement.getCatalog().map(Identifier::getValue).or(session::getCatalog)
.orElseThrow(() -> new IllegalArgumentException("Session default catalog must be set to resolve a partial function name: " + sqlPathElement));
.orElseThrow(() -> new TrinoException(MISSING_CATALOG_NAME, "Session default catalog must be set to resolve a partial function name: " + sqlPathElement));
getOptionalCatalogMetadata(session, catalog).ifPresent(metadata -> {
ConnectorSession connectorSession = session.toConnectorSession(metadata.getCatalogHandle());
functions.addAll(metadata.getMetadata(session).listFunctions(connectorSession, sqlPathElement.getSchema().getValue().toLowerCase(ENGLISH)));
Expand Down

0 comments on commit 55089e9

Please sign in to comment.