grundprinzip commented on code in PR #38037:
URL: https://github.com/apache/spark/pull/38037#discussion_r984802056


##########
python/pyspark/sql/connect/function_builder.py:
##########
@@ -69,33 +74,47 @@ class UserDefinedFunction(Expression):
     the temporary function is set, it is assumed that the registration has 
already
     happened."""
 
-    def __init__(self, func, return_type=pyspark.sql.types.StringType(), 
args=None):
+    def __init__(
+        self,
+        func: Any,
+        return_type: Union[str, pyspark.sql.types.DataType] = 
pyspark.sql.types.StringType(),
+        args: Optional[Iterable[Any]] = None,
+    ) -> None:
         super().__init__()
 
         self._func_ref = func
         self._return_type = return_type
-        self._args = list(args)
+        if args is not None:
+            self._args = list(args)
+        else:
+            self._args = []
         self._func_name = None
 
-    def to_plan(self, session: "RemoteSparkSession") -> Expression:
+    def to_plan(self, session: Optional["RemoteSparkSession"]) -> 
proto.Expression:
+        if session is None:
+            raise Exception("CAnnot create UDF without remote Session.")
         # Needs to materialize the UDF to the server
         # Only do this once per session
         func_name = session.register_udf(self._func_ref, self._return_type)
         # Func name is used for the actual reference
         return _build(func_name, *self._args).to_plan(session)
 
-    def __str__(self):
+    def __str__(self) -> str:
         return f"UserDefinedFunction({self._func_name})"
 
 
-def _create_udf(function, return_type):
-    def wrapper(*cols: "ColumnOrString"):
+def _create_udf(
+    function: Any, return_type: Union[str, pyspark.sql.types.DataType]
+) -> 'Callable[[VarArg("ColumnOrString")], UserDefinedFunction]':

Review Comment:
   will do.



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