Skip to content

Commit 1881f78

Browse files
committed
[SPARK-9086][SQL] Remove BinaryNode from TreeNode.
These traits are not super useful, and yet cause problems with toString in expressions due to the orders they are mixed in.
1 parent affbe32 commit 1881f78

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,24 @@ abstract class Expression extends TreeNode[Expression] {
187187
/**
188188
* A leaf expression, i.e. one without any child expressions.
189189
*/
190-
abstract class LeafExpression extends Expression with trees.LeafNode[Expression] {
190+
abstract class LeafExpression extends Expression {
191191
self: Product =>
192+
193+
def children: Seq[Expression] = Nil
192194
}
193195

194196

195197
/**
196198
* An expression with one input and one output. The output is by default evaluated to null
197199
* if the input is evaluated to null.
198200
*/
199-
abstract class UnaryExpression extends Expression with trees.UnaryNode[Expression] {
201+
abstract class UnaryExpression extends Expression {
200202
self: Product =>
201203

204+
def child: Expression
205+
206+
override def children: Seq[Expression] = child :: Nil
207+
202208
override def foldable: Boolean = child.foldable
203209
override def nullable: Boolean = child.nullable
204210

@@ -271,9 +277,14 @@ abstract class UnaryExpression extends Expression with trees.UnaryNode[Expressio
271277
* An expression with two inputs and one output. The output is by default evaluated to null
272278
* if any input is evaluated to null.
273279
*/
274-
abstract class BinaryExpression extends Expression with trees.BinaryNode[Expression] {
280+
abstract class BinaryExpression extends Expression {
275281
self: Product =>
276282

283+
def left: Expression
284+
def right: Expression
285+
286+
override def children: Seq[Expression] = Seq(left, right)
287+
277288
override def foldable: Boolean = left.foldable && right.foldable
278289

279290
override def nullable: Boolean = left.nullable || right.nullable

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ abstract class UnaryNode extends LogicalPlan with trees.UnaryNode[LogicalPlan] {
291291
/**
292292
* A logical plan node with a left and right child.
293293
*/
294-
abstract class BinaryNode extends LogicalPlan with trees.BinaryNode[LogicalPlan] {
294+
abstract class BinaryNode extends LogicalPlan {
295295
self: Product =>
296+
297+
def left: LogicalPlan
298+
def right: LogicalPlan
299+
300+
override def children: Seq[LogicalPlan] = Seq(left, right)
296301
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,6 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] {
453453
}
454454
}
455455

456-
/**
457-
* A [[TreeNode]] that has two children, [[left]] and [[right]].
458-
*/
459-
trait BinaryNode[BaseType <: TreeNode[BaseType]] {
460-
def left: BaseType
461-
def right: BaseType
462-
463-
def children: Seq[BaseType] = Seq(left, right)
464-
}
465456

466457
/**
467458
* A [[TreeNode]] with no children.

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ private[sql] trait UnaryNode extends SparkPlan with trees.UnaryNode[SparkPlan] {
247247
override def outputPartitioning: Partitioning = child.outputPartitioning
248248
}
249249

250-
private[sql] trait BinaryNode extends SparkPlan with trees.BinaryNode[SparkPlan] {
250+
private[sql] trait BinaryNode extends SparkPlan {
251251
self: Product =>
252+
253+
def left: SparkPlan
254+
def right: SparkPlan
255+
256+
override def children: Seq[SparkPlan] = Seq(left, right)
252257
}

0 commit comments

Comments
 (0)