harshmotw-db opened a new pull request, #50741:
URL: https://github.com/apache/spark/pull/50741

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: 
https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: 
https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a 
faster review.
     7. If you want to add a new configuration, please read the guideline first 
for naming configurations in
        
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the 
guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   
   Prior to this PR, in a very specific codepath in the non-SQL expression 
`MapObjects`, an iterator is returned by df.collect() when codegen is disabled. 
This can lead to non-deterministic behavior when codegen is disabled. For 
example the following code could return incorrect results:
   ```
   spark.conf.set("spark.sql.codegen.factoryMode", "NO_CODEGEN")
   
   import org.apache.spark.sql.Row
   
   case class Posting(transfer_type: String)
   
   val df3 = spark.range(0, 8, 1, 1).selectExpr("""
   case when id = 0 then array(named_struct('a', '1'), named_struct('a', '3'))
   when id = 1 then null
   when id = 2 then null
   when id = 3 then null
   when id = 4 then null
   when id = 5 then null
   when id = 6 then array(named_struct('a', '5'), named_struct('a', '7'))
   else array(named_struct('a', '9'), named_struct('a', '11'))
   end result
   """)
   
   val res6 = df3.select("result").map(row =>
     if (row.get(0) != null) row.get(0).asInstanceOf[Seq[Row]].map(v => 
Posting(v.get(0).asInstanceOf[String]))
     else null
   ).collect()
   ```
   
   ### Why are the changes needed?
   
   The previous code that returned an iterator could give incorrect results 
when a DataFrame represents scala case classes. This PR fixes it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Users could see more deterministic behavior when forcing Interpreted mode 
and using scala objects in DataFrames.
   
   ### How was this patch tested?
   
   Existing tests
   
   ### 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-unsubscr...@spark.apache.org

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


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

Reply via email to