Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-23233

asNondeterministic in Python UDF not being set when the UDF is called at least once

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.0
    • Fix Version/s: 2.3.0
    • Component/s: PySpark, SQL
    • Labels:
      None

      Description

      With this diff

      diff --git a/python/pyspark/sql/udf.py b/python/pyspark/sql/udf.py
      index de96846c5c7..026a78bf547 100644
      --- a/python/pyspark/sql/udf.py
      +++ b/python/pyspark/sql/udf.py
      @@ -180,6 +180,7 @@ class UserDefinedFunction(object):
               wrapper.deterministic = self.deterministic
               wrapper.asNondeterministic = functools.wraps(
                   self.asNondeterministic)(lambda: self.asNondeterministic()._wrapped())
      +        wrapper._unwrapped = lambda: self
               return wrapper
      
           def asNondeterministic(self):
      
      >>> from pyspark.sql.functions import udf
      >>> f = udf(lambda x: x)
      >>> spark.range(1).select(f("id"))
      DataFrame[<lambda>(id): string]
      >>> f._unwrapped()._judf_placeholder.udfDeterministic()
      True
      >>> ndf = f.asNondeterministic()
      >>> ndf.deterministic
      False
      >>> spark.range(1).select(ndf("id"))
      DataFrame[<lambda>(id): string]
      >>> ndf._unwrapped()._judf_placeholder.udfDeterministic()
      True
      

      Seems we don't actually update the deterministic once it's called due to cache in Python side.

        Attachments

          Activity

            People

            • Assignee:
              hyukjin.kwon Hyukjin Kwon
              Reporter:
              hyukjin.kwon Hyukjin Kwon
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: