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

   ### What changes were proposed in this pull request?
   
   Change `TakeOrderedAndProjectExec#executeCollect` and 
`TakeOrderedAndProjectExec#doExecute` to initialize the unsafe projection 
before using it to produce output rows.
   
   ### Why are the changes needed?
   
   Because the unsafe projection is not initialized, non-deterministic 
expressions also don't get initialized. This results in errors when the 
projection contains non-deterministic expressions. For example:
   ```
   create or replace temp view v1(id, name) as values
   (1, "fred"),
   (2, "bob");
   
   cache table v1;
   
   select name, uuid() as _iid from (
     select * from v1 order by name
   )
   limit 20;
   ```
   This query produces the following error:
   ```
   java.lang.NullPointerException: Cannot invoke 
"org.apache.spark.sql.catalyst.util.RandomUUIDGenerator.getNextUUIDUTF8String()"
 because "this.randomGen_0" is null
        at 
org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown
 Source)
        at 
org.apache.spark.sql.execution.TakeOrderedAndProjectExec.$anonfun$executeCollect$6(limit.scala:297)
        at scala.collection.ArrayOps$.map$extension(ArrayOps.scala:934)
        at 
org.apache.spark.sql.execution.TakeOrderedAndProjectExec.$anonfun$executeCollect$1(limit.scala:297)
   ...
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   New 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: [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]

Reply via email to