You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "Tim Armstrong (JIRA)" <ji...@apache.org> on 2018/11/21 23:31:00 UTC

[jira] [Updated] (IMPALA-4939) DECIMAL multiply overflows early

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

Tim Armstrong updated IMPALA-4939:
----------------------------------
    Fix Version/s: Impala 2.11.0

> 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
>            Priority: Major
>             Fix For: Impala 2.11.0
>
>
> 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
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org