HyukjinKwon opened a new pull request, #37552:
URL: https://github.com/apache/spark/pull/37552
### What changes were proposed in this pull request?
This PR proposes to initialize the projection so non-deterministic
expressions can be evaluated with Python UDFs.
### Why are the changes needed?
To make the Python UDF working with non-deterministic expressions.
### Does this PR introduce _any_ user-facing change?
Yes.
```python
from pyspark.sql.functions import udf, rand
spark.range(10).select(udf(lambda x: x, "double")(rand())).show()
```
**Before**
```
java.lang.NullPointerException
at
org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificMutableProjection.apply(Unknown
Source)
at
org.apache.spark.sql.execution.python.EvalPythonExec.$anonfun$doExecute$10(EvalPythonExec.scala:126)
at scala.collection.Iterator$$anon$10.next(Iterator.scala:461)
at scala.collection.Iterator$$anon$10.next(Iterator.scala:461)
at
scala.collection.Iterator$GroupedIterator.takeDestructively(Iterator.scala:1161)
at scala.collection.Iterator$GroupedIterator.go(Iterator.scala:1176)
at scala.collection.Iterator$GroupedIterator.fill(Iterator.scala:1213)
```
**After**
```
+----------------------------------+
|<lambda>rand(-2507211707257730645)|
+----------------------------------+
| 0.7691724424045242|
| 0.09602244075319044|
| 0.3006471278112862|
| 0.4182649571961977|
| 0.29349096650900974|
| 0.7987097908937618|
| 0.5324802583101007|
| 0.72460930912789|
| 0.1367749768412846|
| 0.17277322931919348|
+----------------------------------+
```
### How was this patch tested?
Manually tested, and unittest was added.
--
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]