You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "bersprockets (via GitHub)" <gi...@apache.org> on 2023/09/14 23:02:18 UTC

[GitHub] [spark] bersprockets opened a new pull request, #42933: [SPARK-45171][SQL] Initialize non-deterministic expressions in `GenerateExec`

bersprockets opened a new pull request, #42933:
URL: https://github.com/apache/spark/pull/42933

   ### What changes were proposed in this pull request?
   
   Before evaluating the generator function in `GenerateExec`, initialize non-deterministic expressions.
   
   ### Why are the changes needed?
   
   The following query fails:
   ```
   select *
   from explode(
     transform(sequence(0, cast(rand()*1000 as int) + 1), x -> x * 22)
   );
   
   23/09/14 09:27:25 ERROR Executor: Exception in task 0.0 in stage 3.0 (TID 3)
   java.lang.IllegalArgumentException: requirement failed: Nondeterministic expression org.apache.spark.sql.catalyst.expressions.Rand should be initialized before eval.
   	at scala.Predef$.require(Predef.scala:281)
   	at org.apache.spark.sql.catalyst.expressions.Nondeterministic.eval(Expression.scala:497)
   	at org.apache.spark.sql.catalyst.expressions.Nondeterministic.eval$(Expression.scala:495)
   	at org.apache.spark.sql.catalyst.expressions.RDG.eval(randomExpressions.scala:35)
   	at org.apache.spark.sql.catalyst.expressions.BinaryArithmetic.eval(arithmetic.scala:384)
   	at org.apache.spark.sql.catalyst.expressions.UnaryExpression.eval(Expression.scala:543)
   	at org.apache.spark.sql.catalyst.expressions.BinaryArithmetic.eval(arithmetic.scala:384)
   	at org.apache.spark.sql.catalyst.expressions.Sequence.eval(collectionOperations.scala:3062)
   	at org.apache.spark.sql.catalyst.expressions.SimpleHigherOrderFunction.eval(higherOrderFunctions.scala:275)
   	at org.apache.spark.sql.catalyst.expressions.SimpleHigherOrderFunction.eval$(higherOrderFunctions.scala:274)
   	at org.apache.spark.sql.catalyst.expressions.ArrayTransform.eval(higherOrderFunctions.scala:308)
   	at org.apache.spark.sql.catalyst.expressions.ExplodeBase.eval(generators.scala:375)
   	at org.apache.spark.sql.execution.GenerateExec.$anonfun$doExecute$8(GenerateExec.scala:108)
   ...        
   ```
   However, this query succeeds:
   ```
   select *
   from explode(
     sequence(0, cast(rand()*1000 as int) + 1)
   );
   
   0
   1
   2
   3
   ...
   801
   802
   803
   ```
   The difference is that `transform` turns off whole-stage codegen, which exposes a bug in `GenerateExec` in which the non-deterministic expression passed to the generator function is not initialized before being used.
   
   This PR fixes the bug in `GenerateExec`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   New unit test.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   
   


-- 
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 #42933: [SPARK-45171][SQL] Initialize non-deterministic expressions in `GenerateExec`

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #42933: [SPARK-45171][SQL] Initialize non-deterministic expressions in `GenerateExec`
URL: https://github.com/apache/spark/pull/42933


-- 
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 #42933: [SPARK-45171][SQL] Initialize non-deterministic expressions in `GenerateExec`

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42933:
URL: https://github.com/apache/spark/pull/42933#discussion_r1326624012


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/GenerateExec.scala:
##########
@@ -327,3 +331,4 @@ case class GenerateExec(
   override protected def withNewChildInternal(newChild: SparkPlan): GenerateExec =
     copy(child = newChild)
 }
+

Review Comment:
   ```suggestion
   ```



-- 
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 #42933: [SPARK-45171][SQL] Initialize non-deterministic expressions in `GenerateExec`

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #42933:
URL: https://github.com/apache/spark/pull/42933#issuecomment-1720554821

   Merged to master and branch-3.5.


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