cloud-fan commented on code in PR #48395:
URL: https://github.com/apache/spark/pull/48395#discussion_r1796369501
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -260,19 +260,32 @@ 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)
- if (foldables.size > 1) {
+ if (foldables.nonEmpty) {
val foldableExpr = foldables.reduce((x, y) => Add(x, y, f))
- val c = Literal.create(foldableExpr.eval(EmptyRow), a.dataType)
- if (others.isEmpty) c else Add(others.reduce((x, y) => Add(x, y,
f)), c, f)
+ val foldableValue = foldableExpr.eval(EmptyRow)
+ if (others.isEmpty) {
+ Literal.create(foldableValue, a.dataType)
+ } else if (foldableValue == 0) {
Review Comment:
do we need to consider the NULL semantic? NULL + 0 results to NULL, not 0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]