-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21072][SQL] TreeNode.mapChildren should only apply to the children node. #18284
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line 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 { | ||
|
||
| override def children: Seq[Expression] = sons.flatMap(t => Iterator(t._1, t._2)) | ||
| override def nullable: Boolean = true | ||
| override def dataType: NullType = NullType | ||
| override lazy val resolved = true | ||
| } | ||
|
|
||
| case class JsonTestTreeNode(arg: Any) extends LeafNode { | ||
| override def output: Seq[Attribute] = Seq.empty[Attribute] | ||
| } | ||
|
|
@@ -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))) | ||
|
||
| val before = SeqTupleExpression(children, notChildren) | ||
| val toZero: PartialFunction[Expression, Expression] = { case Literal(_, _) => Literal(0) } | ||
| val expect = SeqTupleExpression(Seq((Literal(0), Literal(0))), notChildren) | ||
|
|
||
| var actual = before transformDown toZero | ||
| assert(actual === expect) | ||
|
|
||
| actual = before transformUp toZero | ||
| assert(actual === expect) | ||
|
|
||
| actual = before transform toZero | ||
|
||
| assert(actual === expect) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe better to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I understand it wrongly. And also you can check it in https://stackoverflow.com/questions/10489548/what-is-the-triple-equals-operator-in-scala-koans |
||
| } | ||
|
|
||
| test("preserves origin") { | ||
| CurrentOrigin.setPosition(1, 1) | ||
| val add = Add(Literal(1), Literal(1)) | ||
|
|
||
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