ulysses-you commented on code in PR #36698:
URL: https://github.com/apache/spark/pull/36698#discussion_r884620087


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Average.scala:
##########
@@ -75,18 +80,17 @@ abstract class AverageBase
   )
 
   protected def getMergeExpressions = Seq(
-    /* sum = */ Add(sum.left, sum.right, useAnsiAdd),
+    /* sum = */ add(sum.left, sum.right),
     /* count = */ count.left + count.right
   )
 
   // If all input are nulls, count will be 0 and we will get null after the 
division.
   // We can't directly use `/` as it throws an exception under ansi mode.
   protected def getEvaluateExpression(queryContext: String) = child.dataType 
match {
     case _: DecimalType =>
-      DecimalPrecision.decimalAndDecimal()(
-        Divide(
-          CheckOverflowInSum(sum, sumDataType.asInstanceOf[DecimalType], 
!useAnsiAdd, queryContext),
-          count.cast(DecimalType.LongDecimal), failOnError = 
false)).cast(resultType)
+      Divide(

Review Comment:
   I think we do not need a `DecimalDivide`, before it was wrapped by 
`DecimalPrecision.decimalAndDecimal()` which applied `PromotePrecision` and 
`CheckOverflow`. This pr makes `Divide` suuport the semantics of 
`PromotePrecision` and `CheckOverflow`, so they are semantically equivalent.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala:
##########
@@ -313,7 +379,7 @@ object BinaryArithmetic {
 case class Add(
     left: Expression,
     right: Expression,
-    failOnError: Boolean = SQLConf.get.ansiEnabled) extends BinaryArithmetic {
+    failOnError: Boolean = SQLConf.get.ansiEnabled) extends DecimalArithmetic {

Review Comment:
   yeah, better to use a trait



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