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

Taras Bobrovytsky resolved IMPALA-4939.
---------------------------------------
    Resolution: Fixed

{code}
commit 6259641077250dcd3360e2e6c2bf9023b201d858
Author: Taras Bobrovytsky <[email protected]>
Date:   Thu Jul 6 10:43:34 2017 -0700

    IMPALA-4939, IMPALA-4940: Decimal V2 multiplication

    Implement the new DECIMAL return type rules for multiply expressions,
    active when query option DECIMAL_V2=1. The algorithm for determining
    the type of the result of multiplication is described in the JIRA.
{code}

> DECIMAL multiply overflows early
> --------------------------------
>
>                 Key: IMPALA-4939
>                 URL: https://issues.apache.org/jira/browse/IMPALA-4939
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>    Affects Versions: Impala 2.9.0
>            Reporter: Dan Hecht
>            Assignee: Taras Bobrovytsky
>
> Decimal multiplication indicates overflow before you've actually overflowed 
> the result type.  For example:
> {code}
> [dhecht-desktop.ca.cloudera.com:21000] > select typeof(cast(.1 as 
> decimal(20,20)) * cast(1 as decimal(20,19)));
> Query: select typeof(cast(.1 as decimal(20,20)) * cast(1 as decimal(20,19)))
> Query submitted at: 2017-02-15 14:08:11 (Coordinator: 
> http://dhecht-desktop.ca.cloudera.com:25000)
> Query progress can be monitored at: 
> http://dhecht-desktop.ca.cloudera.com:25000/query_plan?query_id=ac4e45202a0850c4:c757c44600000000
> +-----------------------------------------------------------------+
> | typeof(cast(0.1 as decimal(20,20)) * cast(1 as decimal(20,19))) |
> +-----------------------------------------------------------------+
> | DECIMAL(38,38)                                                  |
> +-----------------------------------------------------------------+
> [dhecht-desktop.ca.cloudera.com:21000] > select cast(.1 as decimal(20,20)) * 
> cast(1 as decimal(20,19));
> Query: select cast(.1 as decimal(20,20)) * cast(1 as decimal(20,19))
> Query submitted at: 2017-02-15 14:07:58 (Coordinator: 
> http://dhecht-desktop.ca.cloudera.com:25000)
> Query progress can be monitored at: 
> http://dhecht-desktop.ca.cloudera.com:25000/query_plan?query_id=c94daa3dc258be9c:559353e800000000
> +---------------------------------------------------------+
> | cast(0.1 as decimal(20,20)) * cast(1 as decimal(20,19)) |
> +---------------------------------------------------------+
> | NULL                                                    |
> +---------------------------------------------------------+
> WARNINGS: UDF WARNING: Expression overflowed, returning NULL
> [dhecht-desktop.ca.cloudera.com:21000] > select cast(.1 as decimal(20,20)) * 
> cast(1 as decimal(19,18));
> Query: select cast(.1 as decimal(20,20)) * cast(1 as decimal(19,18))
> Query submitted at: 2017-02-15 14:12:48 (Coordinator: 
> http://dhecht-desktop.ca.cloudera.com:25000)
> Query progress can be monitored at: 
> http://dhecht-desktop.ca.cloudera.com:25000/query_plan?query_id=8d4a0189a544e194:12148c3100000000
> +---------------------------------------------------------+
> | cast(0.1 as decimal(20,20)) * cast(1 as decimal(19,18)) |
> +---------------------------------------------------------+
> | 0.10000000000000000000000000000000000000                |
> +---------------------------------------------------------+
> Fetched 1 row(s) in 0.01s
> {code}
> I.e. {{0.1 * 1}} fits in a DECIMAL(38,38), but our implementation of decimal 
> multiply can overflow when S1+S2 > 38 even if the result would fit the result 
> type.
> The problem is that when starting with Decimal16Values, we do a 128 * 128 => 
> 128-bit multiply, rather than 128 * 128 => 256 bit multiply.  We check the 
> intermediate result which has full (S1+S2) scale against 
> MAX_UNSCALED_DECIMAL16, even though we later have code to scale down the 
> result as needed to fit the result type.



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

Reply via email to