Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-15331

Decimal multiplication with high precision/scale often returns NULL

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.0
    • Component/s: Types
    • Labels:
      None
    • Release Note:
      Hide
      The resulting precision/scale of decimal arithmetic has been changed in the case where the precision/scale exceeds the maximum precision of 38.

      When reducing the precision/scale down to the Hive limit of 38, the new behavior is to reduce the scale to preserve the integer portion of the precision, while leaving a minimum of 6 digits for the scale.

      The previous behavior was to always shrink the integer portion of the precision first before the scale.
      Show
      The resulting precision/scale of decimal arithmetic has been changed in the case where the precision/scale exceeds the maximum precision of 38. When reducing the precision/scale down to the Hive limit of 38, the new behavior is to reduce the scale to preserve the integer portion of the precision, while leaving a minimum of 6 digits for the scale. The previous behavior was to always shrink the integer portion of the precision first before the scale.

      Description

      create temporary table dec (a decimal(38,18));
      insert into dec values(100.0);
      
      hive> select a*a from dec;
      OK
      NULL
      Time taken: 0.165 seconds, Fetched: 1 row(s)
      

      Looks like the reason is because the result of decimal(38,18) * decimal(38,18) only has 2 digits of precision for integers:

      hive> set hive.explain.user=false;
      hive> explain select a*a from dec;
      OK
      STAGE DEPENDENCIES:
        Stage-0 is a root stage
      
      STAGE PLANS:
        Stage: Stage-0
          Fetch Operator
            limit: -1
            Processor Tree:
              TableScan
                alias: dec
                Select Operator
                  expressions: (a * a) (type: decimal(38,36))
                  outputColumnNames: _col0
                  ListSink
      
      Time taken: 0.039 seconds, Fetched: 15 row(s)
      

        Attachments

        1. HIVE-15331.3.patch
          57 kB
          Jason Dere
        2. HIVE-15331.2.patch
          10 kB
          Jason Dere
        3. HIVE-15331.1.patch
          10 kB
          Jason Dere

          Issue Links

            Activity

              People

              • Assignee:
                jdere Jason Dere
                Reporter:
                jdere Jason Dere
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: