huaxingao commented on pull request #29695:
URL: https://github.com/apache/spark/pull/29695#issuecomment-702460894


   @maropu 
   Thanks for your comments. I think over this database overflow problem. Spark 
casts to larger data type for SUM, SUM DISTINCT and AVERAGE to prevent 
overflow. If I apply the same casting rules to the pushed down aggregates on 
database side, then probably I can avoid the database overflow problem?
   
   ```
         // Promote SUM, SUM DISTINCT and AVERAGE to largest types to prevent 
overflows.
         case s @ Sum(e @ DecimalType()) => s // Decimal is already the biggest.
         case Sum(e @ IntegralType()) if e.dataType != LongType => Sum(Cast(e, 
LongType))
         case Sum(e @ FractionalType()) if e.dataType != DoubleType => 
Sum(Cast(e, DoubleType))
   
         case s @ Average(e @ DecimalType()) => s // Decimal is already the 
biggest.
         case Average(e @ IntegralType()) if e.dataType != LongType =>
           Average(Cast(e, LongType))
         case Average(e @ FractionalType()) if e.dataType != DoubleType =>
           Average(Cast(e, DoubleType))
   ```
   
   


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

Reply via email to