andygrove opened a new issue, #111:
URL: https://github.com/apache/datafusion-spark/issues/111

   ### Describe the bug
   
   Spark's `avg` returns DECIMAL for DECIMAL input. Our `avg` coerces every 
numeric input to DOUBLE 
([avg.rs#L49](https://github.com/apache/datafusion-spark/blob/main/crates/spark/src/function/aggregate/avg.rs#L49))
 and returns `Float64`. That loses precision and changes the result type. 
DataFusion's built-in `avg` returns DECIMAL for DECIMAL input.
   
   ### To Reproduce
   
   ```sql
   SELECT arrow_typeof(avg(CAST(a AS DECIMAL(10,2)))), avg(CAST(a AS 
DECIMAL(10,2)))
   FROM (VALUES (1), (2)) t(a);
   -- datafusion-spark: Float64, 1.5
   -- Spark 4.2.0: decimal(14,6), 1.500000
   ```
   
   ### Expected behavior
   
   For `DECIMAL(p, s)` input, return `DECIMAL(min(38, p + 4), min(38, s + 4))` 
as Spark does (bounded the way Spark bounds decimal precision), with Spark's 
overflow behavior: NULL when ANSI mode is off, an error when it is on.
   
   ### Additional context
   
   Spark result from PySpark 4.2.0.
   


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