You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/17 10:15:43 UTC

[GitHub] [spark] HyukjinKwon opened a new pull request, #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon closed pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF
URL: https://github.com/apache/spark/pull/37552


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #37552:
URL: https://github.com/apache/spark/pull/37552#issuecomment-1217818228

   cc @cloud-fan


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #37552:
URL: https://github.com/apache/spark/pull/37552#issuecomment-1219002710

   Merged to master, branch-3.3, branch-3.2, and branch-3.1.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #37552:
URL: https://github.com/apache/spark/pull/37552#discussion_r947869640


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvalPythonExec.scala:
##########
@@ -116,6 +116,7 @@ trait EvalPythonExec extends UnaryExecNode {
         }.toArray
       }.toArray
       val projection = MutableProjection.create(allInputs.toSeq, child.output)
+      projection.initialize(context.partitionId())

Review Comment:
   BTW, this is a bandaid fix. To fundamentally fix this, I think we should do something like adding a projection when there's a nondeterministic expression. But this PR doesn't target to fix that. At least this code base is consistent and does not break the intention of `initialize` since `EvalPythonExec` doesn't do anything on partitions, and this is what `ProjectExec` does.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #37552: [SPARK-40121][PYTHON][SQL] Initialize projection used for Python UDF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #37552:
URL: https://github.com/apache/spark/pull/37552#discussion_r947870830


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvalPythonExec.scala:
##########
@@ -116,6 +116,7 @@ trait EvalPythonExec extends UnaryExecNode {
         }.toArray
       }.toArray
       val projection = MutableProjection.create(allInputs.toSeq, child.output)
+      projection.initialize(context.partitionId())

Review Comment:
   The plan from the reproducer above is as follows:
   
   ```
   == Physical Plan ==
   *(2) Project [pythonUDF0#5 AS <lambda>(rand(2977274370236284247))#3]
   +- BatchEvalPython [<lambda>(rand(2977274370236284247))#2], [pythonUDF0#5]
      +- *(1) Project
         +- *(1) Range (0, 10, step=1, splits=16)
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org