-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-21072][SQL] TreeNode.mapChildren should only apply to the children node. #18284
Conversation
@cloud-fan Would you mind take a look? Thanks a lot. |
TreeNode.mapChildren
should only apply to the children node.TreeNode.mapChildren
should only apply to the children node.
ok to test |
good catch! can you add a test in |
Test build #78043 has finished for PR 18284 at commit
|
Thanks for reviewing, I'll add it. |
Test build #78075 has finished for PR 18284 at commit
|
val newChild1 = if (containsChild(arg1)) { | ||
f(arg1.asInstanceOf[BaseType]) | ||
} else { | ||
arg1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can call arg1.asInstanceOf[BaseType]
here, to avoid this change
@@ -61,6 +61,14 @@ case class ExpressionInMap(map: Map[String, Expression]) extends Expression with | |||
override lazy val resolved = true | |||
} | |||
|
|||
case class SeqTupleExpression(sons: Seq[(Expression, Expression)], | |||
notsons: Seq[(Expression, Expression)]) extends Expression with Unevaluable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: nonSons
@@ -146,6 +154,23 @@ class TreeNodeSuite extends SparkFunSuite { | |||
assert(actual === Dummy(None)) | |||
} | |||
|
|||
test("mapChildren should only works on children") { | |||
val children = Seq((Literal(1), Literal(2))) | |||
val notChildren = Seq((Literal(3), Literal(4))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: nonChildren
actual = before transformUp toZero | ||
assert(actual === expect) | ||
|
||
actual = before transform toZero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think testing transform
is good enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we can testing mapChildren
directly
Test build #78081 has started for PR 18284 at commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending tests
@cloud-fan thanks for reviewing, code has updated. |
Test build #78082 has started for PR 18284 at commit |
I can't find the test failed message, seems like unrelated errors. Can you trigger jenkins test again ? because I'm not in the whitelist. Thanks a lot. |
val expect = SeqTupleExpression(Seq((Literal(0), Literal(0))), nonChildren) | ||
|
||
val actual = before mapChildren toZero | ||
assert(actual === expect) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to use .equals
? Although it will call Object's .equals
which is ==
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand it wrongly. ===
compared to ==
could provide more information about the error. You can see the follow examples:
scala> assert(1 == 2)
java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:156)
... 32 elided
scala> assert(1 === 2)
<console>:12: error: value === is not a member of Int
assert(1 === 2)
And also you can check it in https://stackoverflow.com/questions/10489548/what-is-the-triple-equals-operator-in-scala-koans
retest this please |
Nit: The PR title doesn't need to add ``. |
@@ -61,6 +61,14 @@ case class ExpressionInMap(map: Map[String, Expression]) extends Expression with | |||
override lazy val resolved = true | |||
} | |||
|
|||
case class SeqTupleExpression(sons: Seq[(Expression, Expression)], | |||
nonSons: Seq[(Expression, Expression)]) extends Expression with Unevaluable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unevaluable
already extends Expression
. I think you don't need to extend Expression
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks
LGTM |
Test build #78092 has finished for PR 18284 at commit
|
TreeNode.mapChildren
should only apply to the children node.
Test build #78108 has finished for PR 18284 at commit
|
…dren node. ## What changes were proposed in this pull request? Just as the function name and comments of `TreeNode.mapChildren` mentioned, the function should be apply to all currently node children. So, the follow code should judge whether it is the children node. https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala#L342 ## How was this patch tested? Existing tests. Author: Xianyang Liu <xianyang.liu@intel.com> Closes #18284 from ConeyLiu/treenode. (cherry picked from commit 87ab0ce) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…dren node. ## What changes were proposed in this pull request? Just as the function name and comments of `TreeNode.mapChildren` mentioned, the function should be apply to all currently node children. So, the follow code should judge whether it is the children node. https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala#L342 ## How was this patch tested? Existing tests. Author: Xianyang Liu <xianyang.liu@intel.com> Closes #18284 from ConeyLiu/treenode. (cherry picked from commit 87ab0ce) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
thanks, merging to master/2.2/2.1! |
thanks everyone for reviewing. |
…dren node. ## What changes were proposed in this pull request? Just as the function name and comments of `TreeNode.mapChildren` mentioned, the function should be apply to all currently node children. So, the follow code should judge whether it is the children node. https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala#L342 ## How was this patch tested? Existing tests. Author: Xianyang Liu <xianyang.liu@intel.com> Closes apache#18284 from ConeyLiu/treenode.
…dren node. Just as the function name and comments of `TreeNode.mapChildren` mentioned, the function should be apply to all currently node children. So, the follow code should judge whether it is the children node. https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala#L342 Existing tests. Author: Xianyang Liu <xianyang.liu@intel.com> Closes apache#18284 from ConeyLiu/treenode. (cherry picked from commit 87ab0ce) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
Just as the function name and comments of
TreeNode.mapChildren
mentioned, the function should be apply to all currently node children. So, the follow code should judge whether it is the children node.https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala#L342
How was this patch tested?
Existing tests.