mchades commented on code in PR #14505: URL: https://github.com/apache/iceberg/pull/14505#discussion_r2636929383
########## 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: Got it. Thank you for your patience and detailed response. I'm actually facing the same issue, as I've just completed the UDF design for Apache Gravitino and am currently developing it. I believe that the new interface will be very helpful for integrating SQL UDFs with Spark V2 datasource, and I'm looking forward to this feature! -- 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]
