Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

ConeyLiu
Copy link
Contributor

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.

@ConeyLiu
Copy link
Contributor Author

@cloud-fan Would you mind take a look? Thanks a lot.

@ConeyLiu ConeyLiu changed the title [SPARK-21072] TreeNode.mapChildren should only apply to the children node. [SPARK-21072][SQL] TreeNode.mapChildren should only apply to the children node. Jun 13, 2017
@cloud-fan
Copy link
Contributor

ok to test

@cloud-fan
Copy link
Contributor

good catch! can you add a test in TreeNodeSuite?

@SparkQA
Copy link

SparkQA commented Jun 14, 2017

Test build #78043 has finished for PR 18284 at commit f0d5dc9.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ConeyLiu
Copy link
Contributor Author

Thanks for reviewing, I'll add it.

@SparkQA
Copy link

SparkQA commented Jun 15, 2017

Test build #78075 has finished for PR 18284 at commit c3622bb.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

val newChild1 = if (containsChild(arg1)) {
f(arg1.asInstanceOf[BaseType])
} else {
arg1
Copy link
Contributor

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 {
Copy link
Contributor

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)))
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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

@SparkQA
Copy link

SparkQA commented Jun 15, 2017

Test build #78081 has started for PR 18284 at commit 92d4a80.

Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending tests

@ConeyLiu
Copy link
Contributor Author

@cloud-fan thanks for reviewing, code has updated.

@SparkQA
Copy link

SparkQA commented Jun 15, 2017

Test build #78082 has started for PR 18284 at commit 9a9d8af.

@ConeyLiu
Copy link
Contributor Author

ConeyLiu commented Jun 15, 2017

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)
Copy link

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

Copy link
Contributor Author

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

@cloud-fan
Copy link
Contributor

retest this please

@viirya
Copy link
Member

viirya commented Jun 15, 2017

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 {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks

@viirya
Copy link
Member

viirya commented Jun 15, 2017

LGTM

@SparkQA
Copy link

SparkQA commented Jun 15, 2017

Test build #78092 has finished for PR 18284 at commit 9a9d8af.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ConeyLiu ConeyLiu changed the title [SPARK-21072][SQL] TreeNode.mapChildren should only apply to the children node. [SPARK-21072][SQL] TreeNode.mapChildren should only apply to the children node. Jun 15, 2017
@SparkQA
Copy link

SparkQA commented Jun 15, 2017

Test build #78108 has finished for PR 18284 at commit 27fe790.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ExpressionInMap(map: Map[String, Expression]) extends Unevaluable

asfgit pushed a commit that referenced this pull request Jun 16, 2017
…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>
asfgit pushed a commit that referenced this pull request Jun 16, 2017
…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>
@cloud-fan
Copy link
Contributor

thanks, merging to master/2.2/2.1!

@asfgit asfgit closed this in 87ab0ce Jun 16, 2017
@ConeyLiu
Copy link
Contributor Author

thanks everyone for reviewing.

@ConeyLiu ConeyLiu deleted the treenode branch June 16, 2017 05:29
dataknocker pushed a commit to dataknocker/spark that referenced this pull request Jun 16, 2017
…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.
jzhuge pushed a commit to jzhuge/spark that referenced this pull request Aug 20, 2018
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants