rdblue commented on code in PR #5305:
URL: https://github.com/apache/iceberg/pull/5305#discussion_r926043672


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/BaseCatalog.java:
##########
@@ -46,4 +54,56 @@ public Procedure loadProcedure(Identifier ident) throws 
NoSuchProcedureException
 
     throw new NoSuchProcedureException(ident);
   }
+
+  @Override
+  public Identifier[] listFunctions(String[] namespace) throws 
NoSuchNamespaceException {
+    if (isValidNamespaceForFunction(namespace)) {
+      return Arrays.stream(SparkFunctions.list())
+          .map(name -> Identifier.of(namespace, name))
+          .toArray(Identifier[]::new);
+    } else {
+      throw new NoSuchNamespaceException(namespace);
+    }
+  }
+
+  @Override
+  public UnboundFunction loadFunction(Identifier ident) throws 
NoSuchFunctionException {
+    String[] namespace = ident.namespace();
+    String name = ident.name();
+
+    if (isValidNamespaceForFunction(namespace)) {
+      UnboundFunction func = SparkFunctions.load(name);
+      if (func != null) {
+        return func;
+      }
+    }
+
+    throw new NoSuchFunctionException(ident);
+  }
+
+  /**
+   * When in an Iceberg catalog, allow for using the built-in Iceberg 
functions provided that:
+   * <ol>
+   *   <li>
+   *     The namespace is not specified,
+   *     i.e. {@code SELECT truncate(1, 4)} or {@code SELECT 
my_catalog.truncate(1, 4)}
+   *   </li>
+   *   <li>
+   *     The implicit <b>system</b> namespace is used, to mirror call 
procedure syntax,
+   *     i.e. {@code SELECT system.truncate(1, 4)} or {@code SELECT 
my_catalog.system.truncate(1, 4)}
+   *   </li>
+   *   <li>
+   *     A namespace that exists within the catalog is referenced,
+   *     i.e. {@code SELECT ns.truncate(1, 4)} or {@code SELECT 
my_catalog.ns.truncate(1, 4)}

Review Comment:
   Similar to my feedback on the Flink PR, this should not expose functions in 
every database. This should choose a database where Iceberg functions will be 
exposed. I recommend `system` since that's what we use for stored procedures.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to