FANNG1 commented on code in PR #9580:
URL: https://github.com/apache/gravitino/pull/9580#discussion_r2785697060
##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalog.java:
##########
@@ -109,12 +111,45 @@ protected SparkTransformConverter
getSparkTransformConverter() {
@Override
public Identifier[] listFunctions(String[] namespace) throws
NoSuchNamespaceException {
- return ((SparkCatalog) sparkCatalog).listFunctions(namespace);
+ // Get functions from Iceberg catalog
+ Identifier[] icebergFunctions = ((SparkCatalog)
sparkCatalog).listFunctions(namespace);
+
+ // Try to get Gravitino functions. If the namespace doesn't exist in
Gravitino
+ // (e.g., Iceberg's "system" namespace), gracefully return empty array.
+ Identifier[] gravitinoFunctions;
+ if (namespace.length == 0) {
+ gravitinoFunctions = new Identifier[0];
+ } else {
+ try {
+ gravitinoFunctions = super.listFunctions(namespace);
+ } catch (NoSuchNamespaceException e) {
+ // Namespace exists in Iceberg but not in Gravitino, skip Gravitino
functions
+ gravitinoFunctions = new Identifier[0];
+ }
+ }
+
+ // Combine and deduplicate functions, Gravitino functions take precedence
+ Map<String, Identifier> mergedFunctions = new LinkedHashMap<>();
+ for (Identifier id : gravitinoFunctions) {
+ mergedFunctions.put(id.name(), id);
+ }
+ for (Identifier id : icebergFunctions) {
+ mergedFunctions.putIfAbsent(id.name(), id);
+ }
+ return mergedFunctions.values().toArray(new Identifier[0]);
}
@Override
public UnboundFunction loadFunction(Identifier ident) throws
NoSuchFunctionException {
- return ((SparkCatalog) sparkCatalog).loadFunction(ident);
+ try {
+ // When the namespace is empty, to maintain compatibility with Iceberg
behavior, only Iceberg
+ // functions are returned.
+ return ident.namespace().length == 0 &&
ArrayUtils.isEmpty(sparkCatalog.defaultNamespace())
Review Comment:
Could you use sparkCatalog.isFunctionNamespace() to check whether we should
load the function from Gravitino or built-in?
--
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]