xinrong-meng commented on code in PR #39585:
URL: https://github.com/apache/spark/pull/39585#discussion_r1080574085


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -808,6 +808,59 @@ class SparkConnectPlanner(session: SparkSession) {
     }
   }
 
+  /**
+   * Translates a user-defined function from proto to the Catalyst expression.
+   *
+   * @param fun
+   *   Proto representation of the function call.
+   * @return
+   *   Expression.
+   */
+  private def transformScalarInlineUserDefinedFunction(
+      fun: proto.Expression.ScalarInlineUserDefinedFunction): Expression = {
+    fun.getFunctionCase match {
+      case 
proto.Expression.ScalarInlineUserDefinedFunction.FunctionCase.PYTHON_UDF =>
+        transformPythonUDF(fun)
+    }
+  }
+
+  /**
+   * Translates a Python user-defined function from proto to the Catalyst 
expression.
+   *
+   * @param fun
+   *   Proto representation of the function call.
+   * @return
+   *   PythonUDF.
+   */
+  private def transformPythonUDF(
+      fun: proto.Expression.ScalarInlineUserDefinedFunction): PythonUDF = {
+    val udf = fun.getPythonUDF
+    PythonUDF(
+      fun.getFunctionName,
+      transformPythonFunction(udf),
+      DataType.parseTypeWithFallback(
+        schema = udf.getOutputType,
+        parser = DataType.fromDDL,
+        fallbackParser = DataType.fromJson) match {
+        case s: DataType => s
+        case other => throw InvalidPlanInput(s"Invalid return type $other")
+      },
+      fun.getArgumentsList.asScala.map(transformExpression).toSeq,
+      udf.getEvalType,
+      fun.getDeterministic)
+  }
+
+  private def transformPythonFunction(fun: proto.Expression.PythonUDF): 
SimplePythonFunction = {

Review Comment:
   Good idea! Added.



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