Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
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
- is related to
-
IMPALA-1879 mod() function doesn't always interpret fractional arguments as DECIMAL
- Resolved