Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-21125

Sum or Sum0 overflow quietly

    XMLWordPrintableJSON

Details

    Description

      Overflow is not calculated correctly in the build-in sum function of Blink planner.

      For a aggregate calculation such as:

      CREATE TABLE TestTable (
        amount INT
      );
      
      insert into TestTable (2147483647);
      insert into TestTable (1);
      
      SELECT sum(amount) FROM TestTable;
      
      The result will be: -2147483648, which is an overflowed value and no exception was thrown. 

      The overflow occurs quietly and is difficult to detect. 

      Compare the processing semantics of other systems:

      • mysql: provide two SQL mode for handling overflow. If strict SQL mode is enabled, MySQL rejects the out-of-range value with an error, and the insert fails, in accordance with the SQL standard. If no restrictive modes are enabled, MySQL clips the value to the appropriate endpoint of the column data type range and stores the resulting value instead. FYI: https://dev.mysql.com/doc/refman/8.0/en/out-of-range-and-overflow.html
      • presto: all numeric types are automatically cast to Long type, and If the long is out of range, an exception is thrown to prompt user.

      IMO, exception hint is necessary, instead of quietly overflow. 

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            shared_ptr Sebastian Liu
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: