This is an automated email from the ASF dual-hosted git repository. yao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new 319e7cc7d0e7 [SPARK-49628][SQL] ConstantFolding should copy stateful expression before evaluating 319e7cc7d0e7 is described below commit 319e7cc7d0e7ba9a99f808d51a8d635a6159ce8f Author: Wenchen Fan <wenc...@databricks.com> AuthorDate: Fri Sep 13 15:00:53 2024 +0800 [SPARK-49628][SQL] ConstantFolding should copy stateful expression before evaluating ### What changes were proposed in this pull request? It's possible that a logical plan instance is being shared by multiple DFs and these DFs are executed in parallel. Spark always copy stateful expressions before evaluating them, but one place is missed: `ConstantFolding` can also execute expressions. This PR fixes it. ### Why are the changes needed? avoid concurrency issues. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? Not able to write a test for it, but this concurrency issue is quite obvious ### Was this patch authored or co-authored using generative AI tooling? no Closes #48104 from cloud-fan/constant. Authored-by: Wenchen Fan <wenc...@databricks.com> Signed-off-by: Kent Yao <y...@apache.org> --- .../scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala index d0ee9f2d110d..3cdde622d51f 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala @@ -79,7 +79,7 @@ object ConstantFolding extends Rule[LogicalPlan] { // Fold expressions that are foldable. case e if e.foldable => try { - Literal.create(e.eval(EmptyRow), e.dataType) + Literal.create(e.freshCopyIfContainsStatefulExpression().eval(EmptyRow), e.dataType) } catch { case NonFatal(_) if isConditionalBranch => // When doing constant folding inside conditional expressions, we should not fail --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org