Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-999 Casting (legally) to decimal is broken.
  3. IMPALA-997

cast(string as Decimal(x,y)) can be wrong even if the string conforms to the type of decimal it's being cast to.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Impala 1.4
    • Impala 1.4
    • None

    Description

      I wrote a random decimal generator (for a given scale and precision), and ran a series of casts with the generated decimal expressed as a string, and conforming exactly to the scale and precision of the decimal it's being cast to. I occasionally run into something likes this:

      Returned 1 row(s) in 0.17s
      [localhost:21000] > select cast("99.72202762551868586" as Decimal(19,17));
      Query: select cast("99.72202762551868586" as Decimal(19,17))
      +------------------------------------------------+
      | cast('99.72202762551868586' as decimal(19,17)) |
      +------------------------------------------------+
      | -84.74541311157683030                          |
      +------------------------------------------------+
      

      More details:

      [localhost:21000] > select scale(cast("99.72202762551868586" as Decimal(19,17)));
      Query: select scale(cast("99.72202762551868586" as Decimal(19,17)))
      +-------------------------------------------------------+
      | scale(cast('99.72202762551868586' as decimal(19,17))) |
      +-------------------------------------------------------+
      | 17                                                    |
      +-------------------------------------------------------+
      Returned 1 row(s) in 0.18s
      [localhost:21000] > select precision(cast("99.72202762551868586" as Decimal(19,17)));
      Query: select precision(cast("99.72202762551868586" as Decimal(19,17)))
      +-----------------------------------------------------------+
      | precision(cast('99.72202762551868586' as decimal(19,17))) |
      +-----------------------------------------------------------+
      | 19                                                        |
      +-----------------------------------------------------------+
      Returned 1 row(s) in 0.18s
      
      ipython:
      In [1]: num = '99.72202762551868586'
      
      In [2]: print len(num) - 1
      19
      

      Nong, feel free to close this if it's a duplicate, but I haven't found any in-flight change (or jira) that this collides with.

      Attachments

        Activity

          People

            nong_impala_60e1 Nong Li
            ishaan Ishaan Joshi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: