Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-4936

Cast from double to decimal doesn't always handle overflow correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Impala 2.9.0
    • Impala 2.9.0
    • Backend

    Description

      Casting from a double value which will overflow the maximum decimal type should return NULL. It doesn't appear to work as expected all the time when casting from double to decimal when the input value is too large.

      [localhost:21000] > select typeof(555555555555555555555555555555555555555);
      Query: select typeof(555555555555555555555555555555555555555)
      +-------------------------------------------------+
      | typeof(555555555555555555555555555555555555555) |
      +-------------------------------------------------+
      | DOUBLE                                          |
      +-------------------------------------------------+
      Fetched 1 row(s) in 0.01s
      
      [localhost:21000] > select cast(555555555555555555555555555555555555555 as DECIMAL(38,0));
      Query: select cast(555555555555555555555555555555555555555 as DECIMAL(38,0))
      +----------------------------------------------------------------+
      | cast(555555555555555555555555555555555555555 as decimal(38,0)) |
      +----------------------------------------------------------------+
      | 0                                                              |
      +----------------------------------------------------------------+
      Fetched 1 row(s) in 0.01s
      

      It seems to work fine if we are within certain bounds:

      [localhost:21000] > select cast(123456789012345678901234567890123456789 as DECIMAL(38,0));
      Query: select cast(123456789012345678901234567890123456789 as DECIMAL(38,0))
      +----------------------------------------------------------------+
      | cast(123456789012345678901234567890123456789 as decimal(38,0)) |
      +----------------------------------------------------------------+
      | NULL                                                           |
      +----------------------------------------------------------------+
      WARNINGS: UDF WARNING: Expression overflowed, returning NULL
      
      Fetched 1 row(s) in 0.01s
      

      Casting from string seems to work fine:

      [localhost:21000] > select cast('555555555555555555555555555555555555555' as DECIMAL(38,0));
      Query: select cast('555555555555555555555555555555555555555' as DECIMAL(38,0))
      +------------------------------------------------------------------+
      | cast('555555555555555555555555555555555555555' as decimal(38,0)) |
      +------------------------------------------------------------------+
      | NULL                                                             |
      +------------------------------------------------------------------+
      Fetched 1 row(s) in 0.01s
      

      Attachments

        Activity

          People

            zamsden Zach Amsden
            kwho Michael Ho
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: