rkrishn7 commented on issue #17699:
URL: https://github.com/apache/datafusion/issues/17699#issuecomment-3316615098

   Just adding some context here before I forget:
   
   This issue is occurring because there is a logical optimization rule 
(`single_distinct_aggregation_to_group_by`) that rewrites the query, adding a 
new aggregation node. Because the return type for a decimal is calculated by 
adding to the precision 
([ref](https://github.com/apache/datafusion/blob/1629420162815e1a725b9be5344fafd1fbe2e5ff/datafusion/functions-aggregate/src/sum.rs#L190)),
 this occurs twice after the optimization pass. However, type coercion happens 
prior to all of this so the return type later on in the query plan is wrong.
   
   A simple solution would be to re-run type coercion after all optimization 
passes. It seems unnecessary just for this however. The new precision should 
only be updated once, even if there is another aggregation added (since it 
should be equivalent).


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