ueshin opened a new pull request #28774:
URL: https://github.com/apache/spark/pull/28774


   ### What changes were proposed in this pull request?
   
   This PR proposes to make `PythonFunction` holds `Seq[Byte]` instead of 
`Array[Byte]` to be able to compare if the byte array has the same values for 
the cache manager.
   
   ### Why are the changes needed?
   
   Currently the cache manager doesn't use the cache for `udf` if the `udf` is 
created again even if the functions is the same.
   
   ```py
   >>> func = lambda x: x
   
   >>> df = spark.range(1)
   >>> df.select(udf(func)("id")).cache()
   ```
   ```py
   >>> df.select(udf(func)("id")).explain()
   == Physical Plan ==
   *(2) Project [pythonUDF0#14 AS <lambda>(id)#12]
   +- BatchEvalPython [<lambda>(id#0L)], [pythonUDF0#14]
    +- *(1) Range (0, 1, step=1, splits=12)
   ```
   
   This is because `PythonFunction` holds `Array[Byte]`, and `equals` method of 
array equals only when the both array is the same instance.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, if the user reuse the Python function for the UDF, the cache manager 
will detect the same function and use the cache for it.
   
   ### How was this patch tested?
   
   I added a test case and manually.
   
   ```py
   >>> df.select(udf(func)("id")).explain()
   == Physical Plan ==
   InMemoryTableScan [<lambda>(id)#12]
      +- InMemoryRelation [<lambda>(id)#12], StorageLevel(disk, memory, 
deserialized, 1 replicas)
            +- *(2) Project [pythonUDF0#5 AS <lambda>(id)#3]
               +- BatchEvalPython [<lambda>(id#0L)], [pythonUDF0#5]
                  +- *(1) Range (0, 1, step=1, splits=12)
   ```


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

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