[ 
https://issues.apache.org/jira/browse/IMPALA-4964?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Taras Bobrovytsky resolved IMPALA-4964.
---------------------------------------
       Resolution: Fixed
    Fix Version/s: Impala 2.11.0

{code}
IMPALA-4964: Fix Decimal modulo overflow
The modulo operation between two decimals should never overflow. Before
this patch, there would be an overflow if the scale difference between
the two decimals was large. We would try to scale up the one with the
smaller scale, so that the scales matched, which could result in an
overflow.

We fix the problem by first checking if the scaled up value would fit
into 128 bits by estimating the number of leading zeros in it. If we
detect that 128 bits is not enough, we convert both numbers to int256,
do the operation, then convert back to 128 bits.

Testing:
- Added some expr tests that excercise the new code path.

Change-Id: I5420201d4440d421e33e443df005cdcc16b8a6cd
Reviewed-on: http://gerrit.cloudera.org:8080/8329
Reviewed-by: Tim Armstrong <tarmstr...@cloudera.com>
Tested-by: Impala Public Jenkins
{code}

> Decimal modulo operator is overflowing
> --------------------------------------
>
>                 Key: IMPALA-4964
>                 URL: https://issues.apache.org/jira/browse/IMPALA-4964
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>    Affects Versions: Impala 2.9.0
>            Reporter: Zachary
>            Assignee: Taras Bobrovytsky
>             Fix For: Impala 2.11.0
>
>
> Some of the expr test tests were not catching NULL values being produced.  
> The following seems to be getting converted to NULL.
> cast(998 as decimal(38,0)) % cast(0.999 as decimal(38,38))
> cast(0.998 as decimal(38,38)) % cast(999 as decimal(38,0))



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

Reply via email to