Jason Phelps created IMPALA-5936:
------------------------------------

             Summary: Difference between the % Operator and Mod function with 
large decimal values
                 Key: IMPALA-5936
                 URL: https://issues.apache.org/jira/browse/IMPALA-5936
             Project: IMPALA
          Issue Type: Bug
            Reporter: Jason Phelps


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
{quote}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.
{quote} 




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to