Skip to content

Commit 3959d57

Browse files
committed
Fix apply.
1 parent 0acb157 commit 3959d57

File tree

1 file changed

+21
-19
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer

1 file changed

+21
-19
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -752,25 +752,27 @@ object ReorderAssociativeOperator extends Rule[LogicalPlan] {
752752
case other => other :: Nil
753753
}
754754

755-
def apply(plan: LogicalPlan): LogicalPlan = plan transformExpressionsDown {
756-
case a: Add if a.deterministic && a.dataType.isInstanceOf[IntegralType] =>
757-
val (foldables, others) = flattenAdd(a).partition(_.foldable)
758-
if (foldables.size > 1) {
759-
val foldableExpr = foldables.reduce((x, y) => Add(x, y))
760-
val c = Literal.create(foldableExpr.eval(EmptyRow), a.dataType)
761-
if (others.isEmpty) c else Add(others.reduce((x, y) => Add(x, y)), c)
762-
} else {
763-
a
764-
}
765-
case m: Multiply if m.deterministic && m.dataType.isInstanceOf[IntegralType] =>
766-
val (foldables, others) = flattenMultiply(m).partition(_.foldable)
767-
if (foldables.size > 1) {
768-
val foldableExpr = foldables.reduce((x, y) => Multiply(x, y))
769-
val c = Literal.create(foldableExpr.eval(EmptyRow), m.dataType)
770-
if (others.isEmpty) c else Multiply(others.reduce((x, y) => Multiply(x, y)), c)
771-
} else {
772-
m
773-
}
755+
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
756+
case q: LogicalPlan => q transformExpressionsDown {
757+
case a: Add if a.deterministic && a.dataType.isInstanceOf[IntegralType] =>
758+
val (foldables, others) = flattenAdd(a).partition(_.foldable)
759+
if (foldables.size > 1) {
760+
val foldableExpr = foldables.reduce((x, y) => Add(x, y))
761+
val c = Literal.create(foldableExpr.eval(EmptyRow), a.dataType)
762+
if (others.isEmpty) c else Add(others.reduce((x, y) => Add(x, y)), c)
763+
} else {
764+
a
765+
}
766+
case m: Multiply if m.deterministic && m.dataType.isInstanceOf[IntegralType] =>
767+
val (foldables, others) = flattenMultiply(m).partition(_.foldable)
768+
if (foldables.size > 1) {
769+
val foldableExpr = foldables.reduce((x, y) => Multiply(x, y))
770+
val c = Literal.create(foldableExpr.eval(EmptyRow), m.dataType)
771+
if (others.isEmpty) c else Multiply(others.reduce((x, y) => Multiply(x, y)), c)
772+
} else {
773+
m
774+
}
775+
}
774776
}
775777
}
776778

0 commit comments

Comments
 (0)