This is an automated email from the ASF dual-hosted git repository. wenchen 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 dab708e562ac [SPARK-48307][SQL][FOLLOWUP] Eliminate the use of mutable.ArrayBuffer dab708e562ac is described below commit dab708e562acc3f206470b1d4e0598ba3d7c7861 Author: Rui Wang <rui.w...@databricks.com> AuthorDate: Tue Jul 9 08:37:38 2024 +0800 [SPARK-48307][SQL][FOLLOWUP] Eliminate the use of mutable.ArrayBuffer ### What changes were proposed in this pull request? We can eliminate the use of mutable.ArrayBuffer by using `flatmap`. ### Why are the changes needed? Code simplification and optimization. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing UT ### Was this patch authored or co-authored using generative AI tooling? No Closes #47185 from amaliujia/followup_cte. Lead-authored-by: Rui Wang <rui.w...@databricks.com> Co-authored-by: Kent Yao <y...@apache.org> Signed-off-by: Wenchen Fan <wenc...@databricks.com> --- .../apache/spark/sql/catalyst/optimizer/InlineCTE.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala index 8cc25328ce70..19aa1d96ccd3 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala @@ -140,8 +140,7 @@ case class InlineCTE( cteMap: mutable.Map[Long, CTEReferenceInfo]): LogicalPlan = { plan match { case WithCTE(child, cteDefs) => - val notInlined = mutable.ArrayBuffer.empty[CTERelationDef] - cteDefs.foreach { cteDef => + val notInlined = cteDefs.flatMap {cteDef => val refInfo = cteMap(cteDef.id) if (refInfo.refCount > 0) { val newDef = refInfo.cteDef.copy(child = inlineCTE(refInfo.cteDef.child, cteMap)) @@ -149,9 +148,15 @@ case class InlineCTE( cteMap(cteDef.id) = cteMap(cteDef.id).copy( cteDef = newDef, shouldInline = inlineDecision ) - if (!inlineDecision) notInlined += newDef + if (!inlineDecision) { + Seq(newDef) + } else { + Nil + } } else if (keepDanglingRelations) { - notInlined += refInfo.cteDef + Seq(refInfo.cteDef) + } else { + Nil } } val inlined = inlineCTE(child, cteMap) @@ -159,7 +164,7 @@ case class InlineCTE( inlined } else { // Retain the not-inlined CTE relations in place. - WithCTE(inlined, notInlined.toSeq) + WithCTE(inlined, notInlined) } case ref: CTERelationRef => --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org