You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Wenchen Fan (Jira)" <ji...@apache.org> on 2025/04/29 00:45:00 UTC

[jira] [Assigned] (SPARK-51935) Lazy behavior of Iterators causing correctness issue in df.collect() when codegen is disabled

     [ https://issues.apache.org/jira/browse/SPARK-51935?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wenchen Fan reassigned SPARK-51935:
-----------------------------------

    Assignee: Harsh Motwani

> Lazy behavior of Iterators causing correctness issue in df.collect() when codegen is disabled
> ---------------------------------------------------------------------------------------------
>
>                 Key: SPARK-51935
>                 URL: https://issues.apache.org/jira/browse/SPARK-51935
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Core
>    Affects Versions: 3.5.0, 4.0.0
>            Reporter: Harsh Motwani
>            Assignee: Harsh Motwani
>            Priority: Major
>              Labels: pull-request-available
>
> This block of code can produce incorrect results because the relevant codepath returns an iterator which is lazily evaluated when needed instead of a materialized list. The issue is coming from [this line|https://github.com/apache/spark/blob/d4513013ea704ae888a38db6b1f4159165db0b1a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala#L995]. cc [~cloud_fan]
> {code:java}
> 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()
> res6.foreach(e => println(if (e ne null) e.toVector else null))
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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