rdtr opened a new issue, #60479: URL: https://github.com/apache/spark/issues/60479
Mirror of https://issues.apache.org/jira/browse/SPARK-61676. `ConstantFolding` folds the children of a non-foldable conditional expression (`If`, `CaseWhen`, `Coalesce`, ...) but does not check the conditional itself again. A child can become a literal in that pass: a `ScalarSubquery` whose plan has `maxRows == 0` becomes a null literal (SPARK-44527), and `size(array(a))` becomes its length. The conditional is then foldable but stays unfolded, so a second run of the rule changes the plan again. Other expressions are folded again after their children since SPARK-53360. For example, one run of `ConstantFolding` turns ```sql SELECT coalesce((SELECT 1 FROM range(1) WHERE false), 2) AS c FROM range(3) ``` into `coalesce(null, 2)` instead of `2`. The operator optimization batch runs to a fixed point, so the final plan of this query is folded. A batch that runs the rule with the `Once` strategy, like the one in `ConstantFoldingSuite`, fails instead: ``` org.apache.spark.SparkRuntimeException: Once strategy's idempotence is broken for batch ConstantFolding !Project [coalesce(null, 2) AS o#5] Project [2 AS o#5] +- LocalRelation <empty>, [a#0, b#1, c#2] +- LocalRelation <empty>, [a#0, b#1, c#2]. ``` Proposed fix: after folding the children of a conditional expression, fold the result when it is foldable, as the other expressions do. -- 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]
