[ 
https://issues.apache.org/jira/browse/CALCITE-5181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17550300#comment-17550300
 ] 

Benchao Li commented on CALCITE-5181:
-------------------------------------

Yes, this has been around for a long time, we discovered this in FLINK-21125 
before.

There are two parts of this problem:
 # what's the correct result type for {{SUM}}
 # what's the runtime behavior should be when the calculation overflows. (Of 
course, this is a more general topic, not only for {{SUM}}, but also for all 
the numeric calculations)

For the #1, maybe we can consult the SQL standard.
For the #2, I'm always in favor of explicitly throwing exception rather than 
overflowing quietly.

> Sum aggregate function return wong result
> -----------------------------------------
>
>                 Key: CALCITE-5181
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5181
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.30.0
>            Reporter: xiong duan
>            Priority: Major
>
> To reproduce(dummy.iq):
> {code:java}
> !use scott
> !set outputformat mysql
> SELECT sum(empno) from "scott".emp; {code}
> Should return 108172, but return -22900.
> This is because RelDataTypeSystemImpl deriveSumType return a wrong datatype. 
> We presume when the parameter is smllInt, the return datatype stay same as 
> the parameter. So the result out of range.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to