HyukjinKwon commented on code in PR #39585:
URL: https://github.com/apache/spark/pull/39585#discussion_r1081248787
##########
python/pyspark/sql/connect/functions.py:
##########
@@ -2350,8 +2356,21 @@ def unwrap_udt(col: "ColumnOrName") -> Column:
unwrap_udt.__doc__ = pysparkfuncs.unwrap_udt.__doc__
-def udf(*args: Any, **kwargs: Any) -> None:
- raise NotImplementedError("udf() is not implemented.")
+def udf(
+ f: Optional[Union[Callable[..., Any], "DataTypeOrString"]] = None,
+ returnType: "DataTypeOrString" = StringType(),
+) -> Union["UserDefinedFunctionLike", Callable[[Callable[..., Any]],
"UserDefinedFunctionLike"]]:
+ if f is None or isinstance(f, (str, DataType)):
+ # If DataType has been passed as a positional argument
+ # for decorator use it as a returnType
+ return_type = f or returnType
+ return functools.partial(
+ _create_udf, returnType=return_type, evalType=100 #
PythonEvalType.SQL_BATCHED_UDF
Review Comment:
That's actually also used in Python RDD, and Python UDF is based on the top
of RDD so it's not that bad :-).
Xinrong, you can import `PythonEvalType.SQL_BATCHED_UDF` within this
function to avoid cyclic import
--
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]