mchades commented on code in PR #14505:
URL: https://github.com/apache/iceberg/pull/14505#discussion_r2634334626


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/udf/SparkUDFRegistrar.java:
##########
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.udf;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.spark.functions.UserSqlFunctions;
+import org.apache.iceberg.udf.UdfSpecResolver.Param;
+import org.apache.iceberg.udf.UdfSpecResolver.ResolvedSpec;
+import org.apache.spark.sql.SparkSession;
+
+/**
+ * Registers SQL UDFs in a SparkSession from Iceberg UDF metadata JSON.
+ *
+ * <p>This utility parses a function specification (see Iceberg function spec) 
using {@link
+ * org.apache.iceberg.udf.UdfSpecResolver}, filters to the requested dialect 
("spark"), and
+ * materializes one Spark 4.0 SQL UDF per matching overload by executing 
{@code CREATE OR REPLACE
+ * TEMPORARY FUNCTION ... RETURN SQL} DDL.
+ *
+ * <p>Both scalar and table-valued functions (UDTF) are supported. Overloads 
are registered under
+ * the same function name with parameter-type-specific signatures so Spark's 
analyzer can resolve
+ * the appropriate implementation at call time.
+ *
+ * <p>Functions registered here are session-scoped. For discovery via 
Iceberg's FunctionCatalog, the
+ * function name is also recorded in {@link 
org.apache.iceberg.spark.functions.UserSqlFunctions}.

Review Comment:
   may I ask a question anout the design?
   
   Since a function is located within a specific namespace, it means that two 
functions with identical signatures can exist under different namespaces, such 
as `ns1.funcA()` and `ns2.funcA`, both of which are valid.
   
   How to ensure that the SQL statement `select ns1.funcA(), ns2.funcA()` can 
be executed properly? Because the UDF registered in a Spark session is 
session-scoped, meaning that once `ns1.funcA` is registered, `ns2.funcA` cannot 
be registered in the same session, as they use the same function name `funcA`.



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