neilconway opened a new issue, #25943: URL: https://github.com/apache/datafusion/issues/25943
### Describe the bug A query with two or more `SUM(<expr> + <literal>)` aggregates over the same `<expr>` can: - fail to plan, - fail at execution, or - return a different result type than the same aggregate on its own. Each aggregate works when it is the only one in the query. ### To Reproduce ```sql CREATE TABLE t AS SELECT CAST(v AS DECIMAL(10,2)) AS d, CAST(v || ' days' AS INTERVAL) AS iv FROM generate_series(1, 12) AS g(v); -- Interval literals (default configuration) SELECT SUM(iv + INTERVAL '1 day') AS a FROM t; -- 90 days SELECT SUM(iv + INTERVAL '1 day') AS a, SUM(iv + INTERVAL '2 days') AS b FROM t; -- Optimizer rule 'simplify_expressions' failed -- caused by -- Error during planning: Cannot get result type for temporal operation Interval(MonthDayNano) * Interval(MonthDayNano): Invalid argument error: Invalid interval arithmetic operation: Interval(MonthDayNano) * Interval(MonthDayNano) -- Decimal literals SET datafusion.sql_parser.parse_float_as_decimal = true; SELECT SUM(d + 1.5) AS a FROM t; -- 96.00 SELECT SUM(d + 1.5) AS a, SUM(d + 2.5) AS b FROM t; -- Failed to cast field 'count(t.d)' from Int64 to Decimal128(2, 1) -- caused by -- Arrow error: Invalid argument error: 12.0 is too large to store in a Decimal128 of precision 2. Max is 9.9 -- On fewer rows the query runs, but the result type changes SELECT SUM(d + 1.00001) AS a, arrow_typeof(SUM(d + 1.00001)) AS a_type FROM t WHERE d <= 5; -- 20.00005 | Decimal128(24, 5) SELECT SUM(d + 1.00001) AS a, arrow_typeof(SUM(d + 1.00001)) AS a_type, SUM(d + 2.00001) AS b FROM t WHERE d <= 5; -- 20.0000500000 | Decimal128(29, 10) | 25.0000500000 ``` ### Expected behavior Each aggregate returns the same value and type as when it is the only aggregate in the query: - `90 days` and `102 days` - `96.00` and `108.00` - `20.00005` and `25.00005`, both `Decimal128(24, 5)` ### Additional context Reproduced on `main` at commit 2b1fcae86, in both release and debug builds. *This bug report was generated by Claude.* -- 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]
