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

Difference between the % Operator and Mod function with large decimal values

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Impala 2.11.0
    • Component/s: Frontend
    • Labels:
      None
    • Epic Color:
      ghx-label-1

      Description

      It looks like the '%' operator breaks in the following scenario:

      decimal(18,0) + Any value greater than INT (2147483647)

      As far as I can tell, `%` will typically use the proper mod function transparently, but instead of using/casting as BIGINT, it will use INT, and then overflow. If I directly cast as BIGINT, it will work as expected.

      num num % 3 mod(num, 3)
      42607032167 -2 2
      42606774111 -1 0
      42363009429 -1 0
      42603003271 0 1
      42606961501 0 1
      42608445511 0 1
      42607368197 -2 2
      42606319059 -1 0
      42602678339 -2 2
      42260146355 -2 2

      If the number is used directly (i.e. not using a column), it works as expected:

      42607032167 % 3 mod(42607032167, 3)
      2 2

      According to the documentation, these should be equivalent

      mod(numeric_type a, same_type b)
      Purpose: Returns the modulus of a number. Equivalent to the % arithmetic operator. Works with any size integer type, any size floating-point type, and DECIMAL with any precision and scale.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                boroknagyz Zoltán Borók-Nagy
                Reporter:
                jphelps Jason Phelps
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: