You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "Zouxxyy (via GitHub)" <gi...@apache.org> on 2025/08/14 05:26:53 UTC

Re: [PR] [spark] Add v1 function support to SparkCatalog [paimon]

Zouxxyy commented on code in PR #6075:
URL: https://github.com/apache/paimon/pull/6075#discussion_r2275477494


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalog/functions/V1FunctionConverter.scala:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.paimon.spark.catalog.functions
+
+import org.apache.paimon.catalog.Identifier
+import org.apache.paimon.function.{Function, FunctionDefinition, FunctionImpl}
+import org.apache.paimon.spark.SparkCatalog.FUNCTION_DEFINITION_NAME
+
+import org.apache.spark.sql.catalyst.FunctionIdentifier
+import org.apache.spark.sql.catalyst.catalog.{CatalogFunction, FunctionResource, FunctionResourceType}
+
+import scala.collection.JavaConverters._
+
+object V1FunctionConverter {
+
+  /** Converts spark [[FunctionIdentifier]] to paimon [[Identifier]]. */
+  def fromFunctionIdentifier(ident: FunctionIdentifier): Identifier = {
+    new Identifier(ident.database.get, ident.funcName)
+  }
+
+  /** Converts paimon [[Identifier]] to spark [[FunctionIdentifier]]. */
+  def toFunctionIdentifier(ident: Identifier): FunctionIdentifier = {
+    new FunctionIdentifier(ident.getObjectName, Some(ident.getDatabaseName))
+  }
+
+  /** Converts spark [[CatalogFunction]] to paimon [[Function]]. */
+  def fromV1Function(v1Function: CatalogFunction): Function = {
+    val functionIdentifier = v1Function.identifier
+    val identifier = fromFunctionIdentifier(functionIdentifier)
+    val fileResources = v1Function.resources
+      .map(r => new FunctionDefinition.FunctionFileResource(r.resourceType.resourceType, r.uri))
+      .toList
+
+    val functionDefinition: FunctionDefinition = FunctionDefinition.file(
+      fileResources.asJava,
+      "",

Review Comment:
   Since Spark's function metadata not include the `language`, I am passing an empty string, or maybe null?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org