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


##########
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:
   This TEMPORARY FUNCTION path is just a quick POC to prove the JSON spec -> 
Spark SQL execution works. It’s intentionally “hacky”: it mutates session state 
and flattens names, so ns1.funcA and ns2.funcA collide in the same session.
   The real implementation won’t register temp functions. Analyzer rule will be 
used instead to resolve each call per-catalog (qualified identifiers).



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