Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20137#discussion_r159582570
  
    --- Diff: python/pyspark/sql/catalog.py ---
    @@ -255,9 +255,26 @@ def registerFunction(self, name, f, 
returnType=StringType()):
             >>> _ = spark.udf.register("stringLengthInt", len, IntegerType())
             >>> spark.sql("SELECT stringLengthInt('test')").collect()
             [Row(stringLengthInt(test)=4)]
    +
    +        >>> import random
    +        >>> from pyspark.sql.functions import udf
    +        >>> from pyspark.sql.types import IntegerType, StringType
    +        >>> random_udf = udf(lambda: random.randint(0, 100), 
IntegerType()).asNondeterministic()
    +        >>> newRandom_udf = spark.catalog.registerFunction("random_udf", 
random_udf, StringType())
    +        >>> spark.sql("SELECT random_udf()").collect()  # doctest: +SKIP
    +        [Row(random_udf()=u'82')]
    +        >>> spark.range(1).select(newRandom_udf()).collect()  # doctest: 
+SKIP
    +        [Row(random_udf()=u'62')]
             """
    -        udf = UserDefinedFunction(f, returnType=returnType, name=name,
    -                                  evalType=PythonEvalType.SQL_BATCHED_UDF)
    +
    +        # This is to check whether the input function is a wrapped/native 
UserDefinedFunction
    +        if hasattr(f, 'asNondeterministic'):
    +            udf = UserDefinedFunction(f.func, returnType=returnType, 
name=name,
    +                                      
evalType=PythonEvalType.SQL_BATCHED_UDF,
    --- End diff --
    
    cc @ueshin @icexelloss , shall we support register pandas UDF here too?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to