jerryshao commented on code in PR #9580:
URL: https://github.com/apache/gravitino/pull/9580#discussion_r2785648161
##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java:
##########
@@ -437,17 +444,72 @@ protected String getDatabase(Identifier sparkIdentifier) {
return getCatalogDefaultNamespace();
}
+ @Override
+ public Identifier[] listFunctions(String[] namespace) throws
NoSuchNamespaceException {
+ String gravitinoNamespace;
+ if (namespace.length == 0) {
+ gravitinoNamespace = getCatalogDefaultNamespace();
+ } else {
+ validateNamespace(namespace);
+ gravitinoNamespace = namespace[0];
+ }
+ try {
+ Function[] functions =
+ gravitinoCatalogClient
+ .asFunctionCatalog()
+ .listFunctionInfos(Namespace.of(gravitinoNamespace));
+ // Filter functions that have Spark runtime implementation
+ return Arrays.stream(functions)
+ .filter(this::hasSparkImplementation)
+ .map(f -> Identifier.of(new String[] {gravitinoNamespace}, f.name()))
+ .toArray(Identifier[]::new);
+ } catch (NoSuchSchemaException e) {
+ throw new NoSuchNamespaceException(namespace);
+ }
+ }
+
+ @Override
+ public UnboundFunction loadFunction(Identifier ident) throws
NoSuchFunctionException {
+ String[] namespace = ident.namespace();
+ if (namespace.length == 0) {
+ namespace = new String[] {getCatalogDefaultNamespace()};
+ ident = Identifier.of(namespace, ident.name());
+ }
+ validateNamespace(namespace);
+
+ NameIdentifier gravitinoIdentifier = NameIdentifier.of(getDatabase(ident),
ident.name());
+ try {
+ Function function =
+
gravitinoCatalogClient.asFunctionCatalog().getFunction(gravitinoIdentifier);
+ for (FunctionDefinition definition : function.definitions()) {
+ for (FunctionImpl impl : definition.impls()) {
+ if (!isSparkImplementation(impl)) {
+ continue;
+ }
+ String className = extractClassName(impl);
+ if (StringUtils.isBlank(className)) {
+ continue;
+ }
+ return instantiateFunction(className, ident);
Review Comment:
Is it possible that there are multiple Spark impls in the different
definitions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]