Skip to content
Snippets Groups Projects
Commit d9660867 authored by scwf's avatar scwf Committed by Michael Armbrust
Browse files

[SQL][Minor] Fix foreachUp of treenode

`foreachUp` should runs the given function recursively on [[children]] then on this node(just like transformUp). The current implementation does not follow this.

This will leads to checkanalysis do not check from bottom of logical tree.

Author: scwf <wangfei1@huawei.com>
Author: Fei Wang <wangfei1@huawei.com>

Closes #5518 from scwf/patch-1 and squashes the following commits:

18e28b2 [scwf] added a test case
1ccbfa8 [Fei Wang] fix foreachUp
parent 6183b5e2
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] {
* @param f the function to be applied to each node in the tree.
*/
def foreachUp(f: BaseType => Unit): Unit = {
children.foreach(_.foreach(f))
children.foreach(_.foreachUp(f))
f(this)
}
......
......@@ -117,5 +117,17 @@ class TreeNodeSuite extends FunSuite {
assert(transformed.origin.startPosition.isDefined)
}
test("foreach up") {
val actual = new ArrayBuffer[String]()
val expected = Seq("1", "2", "3", "4", "-", "*", "+")
val expression = Add(Literal(1), Multiply(Literal(2), Subtract(Literal(3), Literal(4))))
expression foreachUp {
case b: BinaryExpression => actual.append(b.symbol);
case l: Literal => actual.append(l.toString);
}
assert(expected === actual)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment