sigmod commented on a change in pull request #32030:
URL: https://github.com/apache/spark/pull/32030#discussion_r609940832



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala
##########
@@ -246,11 +246,50 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] 
extends Product {
     arr
   }
 
+  private def childrenTheSame(
+      originalChildren: IndexedSeq[BaseType], newChildren: 
IndexedSeq[BaseType]): Boolean = {
+    val size = originalChildren.size
+    var i = 0
+    var childrenTheSame = true
+    while (i < size && childrenTheSame) {
+      childrenTheSame &&= originalChildren(i) fastEquals newChildren(i)
+      i += 1
+    }
+    childrenTheSame
+  }
+
+  // This is a temporary solution, we will change the type of children to 
IndexedSeq in a
+  // followup PR
+  private def asIndexedSeq(seq: Seq[BaseType]): IndexedSeq[BaseType] = {
+    if (seq.isInstanceOf[IndexedSeq[BaseType]]) {
+      seq.asInstanceOf[IndexedSeq[BaseType]]
+    } else {
+      seq.toIndexedSeq
+    }
+  }
+
+  def withNewChildren(newChildren: Seq[BaseType]): BaseType = {
+    val childrenIndexedSeq = asIndexedSeq(children)
+    val newChildrenIndexedSeq = asIndexedSeq(newChildren)
+    assert(newChildrenIndexedSeq.size == childrenIndexedSeq.size, "Incorrect 
number of children")
+    if (childrenIndexedSeq.isEmpty || childrenTheSame(newChildrenIndexedSeq, 
childrenIndexedSeq)) {
+      this
+    } else {
+      CurrentOrigin.withOrigin(origin) {
+        val res = withNewChildrenInternal(newChildrenIndexedSeq)
+        res.copyTagsFrom(this)
+        res
+      }
+    }
+  }
+
+  protected def withNewChildrenInternal(newChildren: IndexedSeq[BaseType]): 
BaseType

Review comment:
       Ok, makes sense. Thanks for the elaboration!




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

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