Skip to content

Commit

Permalink
[WIP][SPARK-49915][SQL] Handle zeros and ones in ReorderAssociativeOp…
Browse files Browse the repository at this point in the history
…erator
  • Loading branch information
yaooqinn committed Oct 9, 2024
1 parent 3420912 commit 1800fcc
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ object ReorderAssociativeOperator extends Rule[LogicalPlan] {
q.transformExpressionsDownWithPruning(_.containsPattern(BINARY_ARITHMETIC)) {
case a @ Add(_, _, f) if a.deterministic && a.dataType.isInstanceOf[IntegralType] =>
val (foldables, others) = flattenAdd(a, groupingExpressionSet).partition(_.foldable)
val newExpr = if (foldables.nonEmpty) {
if (foldables.nonEmpty) {
val foldableExpr = foldables.reduce((x, y) => Add(x, y, f))
val foldableValue = foldableExpr.eval(EmptyRow)
val c = Literal.create(foldableValue, a.dataType)
if (others.isEmpty) {
Literal.create(foldableValue, a.dataType)
} else if (foldableValue == 0) {
Expand All @@ -274,10 +273,9 @@ object ReorderAssociativeOperator extends Rule[LogicalPlan] {
} else {
a
}
newExpr
case m @ Multiply(_, _, f) if m.deterministic && m.dataType.isInstanceOf[IntegralType] =>
val (foldables, others) = flattenMultiply(m, groupingExpressionSet).partition(_.foldable)
val newExpr = if (foldables.nonEmpty) {
if (foldables.nonEmpty) {
val foldableExpr = foldables.reduce((x, y) => Multiply(x, y, f))
val foldableValue = foldableExpr.eval(EmptyRow)
if (others.isEmpty || foldableValue == 0) {
Expand All @@ -291,7 +289,6 @@ object ReorderAssociativeOperator extends Rule[LogicalPlan] {
} else {
m
}
newExpr
}
}
}
Expand Down

0 comments on commit 1800fcc

Please sign in to comment.