cloud-fan commented on a change in pull request #29882:
URL: https://github.com/apache/spark/pull/29882#discussion_r504485906
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Average.scala
##########
@@ -77,11 +77,16 @@ case class Average(child: Expression) extends
DeclarativeAggregate with Implicit
)
// If all input are nulls, count will be 0 and we will get null after the
division.
- override lazy val evaluateExpression = child.dataType match {
- case _: DecimalType =>
- DecimalPrecision.decimalAndDecimal(sum /
count.cast(DecimalType.LongDecimal)).cast(resultType)
- case _ =>
- sum.cast(resultType) / count.cast(resultType)
+ // We can't directly use `Divide` as it throws an exception under ansi mode.
Review comment:
can we put `failOnError` as a constructor parameter in `Divide`, like
what @leanken did to the statistical aggregate functions? Then here we just
need to write `Divide(sum.cast(resultType), count.cast(resultType), failOnError
= false)`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]