HyukjinKwon commented on code in PR #37137:
URL: https://github.com/apache/spark/pull/37137#discussion_r917171663


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/linearRegression.scala:
##########
@@ -278,7 +278,8 @@ case class RegrSlope(left: Expression, right: Expression) 
extends DeclarativeAgg
     covarPop.mergeExpressions ++ varPop.mergeExpressions
 
   override lazy val evaluateExpression: Expression = {
-    If(covarPop.n === 0.0, Literal.create(null, DoubleType), covarPop.ck / 
varPop.m2)
+    If(Or(covarPop.n === 0.0, varPop.m2 === 0.0),

Review Comment:
   Will remove `covarPop`. 
   
   BTW, I think this is a bug fix. Such null behaviour is consistent everywhere 
in other aggregate functions that use divisions, see also
   
   ```scala
   scala> spark.conf.set("spark.sql.ansi.enabled", true)
   
   scala> spark.range(1).selectExpr("sum(null)").show()
   +---------+
   |sum(NULL)|
   +---------+
   |     null|
   +---------+
   ```
   
   It's more null propagation that failed before. ANSI documentation doesn't 
mention about null handling from my cursory look so I think we can just keep ti 
consistent within our codebase



-- 
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]

Reply via email to