yaooqinn commented on code in PR #46552:
URL: https://github.com/apache/spark/pull/46552#discussion_r1601246965


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/With.scala:
##########
@@ -40,7 +40,23 @@ case class With(child: Expression, defs: 
Seq[CommonExpressionDef])
   override def children: Seq[Expression] = child +: defs
   override protected def withNewChildrenInternal(
       newChildren: IndexedSeq[Expression]): Expression = {
-    copy(child = newChildren.head, defs = 
newChildren.tail.map(_.asInstanceOf[CommonExpressionDef]))
+    val newDefs = newChildren.tail.map(_.asInstanceOf[CommonExpressionDef])
+    // If any `CommonExpressionDef` has been updated (data type or 
nullability), also update its
+    // `CommonExpressionRef` in the `child`.
+    val newChild = newDefs.filter(_.resolved).foldLeft(newChildren.head) { 
(result, newDef) =>
+      defs.find(_.id == newDef.id).map { oldDef =>
+        if (newDef.dataType != oldDef.dataType || newDef.nullable != 
oldDef.nullable) {
+          val newRef = new CommonExpressionRef(newDef)
+          result.transform {
+            case oldRef: CommonExpressionRef if oldRef.id == newRef.id =>

Review Comment:
   Nit: We can use oldRef.id == newD~F~ef.id to avoid creating some newRef?



-- 
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]

Reply via email to