You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@impala.apache.org by "Taras Bobrovytsky (JIRA)" <ji...@apache.org> on 2018/02/02 01:18:00 UTC

[jira] [Resolved] (IMPALA-6429) Decimal division returns an incorrect result

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

Taras Bobrovytsky resolved IMPALA-6429.
---------------------------------------
       Resolution: Fixed
    Fix Version/s: Impala 3.0

{noformat}
commit 4bd7cc8dbf2f07db3468e1feb595cd16a7cd81e3
Author: Taras Bobrovytsky <tb...@cloudera.com>
Date: Tue Jan 23 15:19:59 2018 -0800

IMPALA-6429: Fix decimal division

Before this patch, it was possible for an overflow to not be detected
when doing a decimal division. When scaling up the dividend before
doing the division, we do not check for overflow. This is ok if the
we are scaling up by 10^38 or less because the result is guaranteed to
fit into 256 bits. However, when we are scaling up by more than 38, the
result may not fit into 256 bits and overflow. This overflow may not be
detected.

The problem is fixed by checking for overflow when scaling up the
dividend. The overflow check is done efficiently, by counting the
leading zeros. I added a test to prove that this check is correct.

Testing:
- Added some BE tests
- I ran a few benchmarks and did not see any performance regressions

Change-Id: Ibd1075d9c78986cd975dd29c1125d71ba6560c23
Reviewed-on: http://gerrit.cloudera.org:8080/9114
Reviewed-by: Taras Bobrovytsky <tb...@cloudera.com>
Tested-by: Impala Public Jenkins{noformat}

> Decimal division returns an incorrect result
> --------------------------------------------
>
>                 Key: IMPALA-6429
>                 URL: https://issues.apache.org/jira/browse/IMPALA-6429
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>    Affects Versions: Impala 2.11.0
>            Reporter: Taras Bobrovytsky
>            Assignee: Taras Bobrovytsky
>            Priority: Blocker
>              Labels: broken-build
>             Fix For: Impala 3.0
>
>
> This bug was found by the decimal fuzzer in one of our exhaustive nigthly builds.
> Query:
> {code:java}
> select cast(9269574547799442144750864826042582 as decimal(38,2)) / cast(-0.2475880078570760549798248447 as decimal(38,38))
> {code}
> Result:
> {code:java}
> -25071524537367060442348433289920.875272
> {code}
> The expected results should be around:
> {code:java}
> -37439513440208481766456680165938338.924
> {code}
> I computed the expected result in Python. Even without a calculator, it should be obvious that the first digit of the expected result should be higher than 2.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)