[ 
https://issues.apache.org/jira/browse/HIVE-14281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15384742#comment-15384742
 ] 

Chaoyu Tang commented on HIVE-14281:
------------------------------------

For Java BigDecimal, there is a comment about the rounding and wonder if it can 
be used in Hive
{code}
Before rounding, the scale of the logical exact intermediate result (e.g. 
multiplier.scale() + multiplicand.scale()) is the preferred scale for that 
operation (e.g. multiply). If the exact numerical result cannot be represented 
in precision digits, rounding selects the set of digits to return and the scale 
of the result is reduced from the scale of the intermediate result to the least 
scale which can represent the precision digits actually returned. If the exact 
result can be represented with at most precision digits, the representation of 
the result with the scale closest to the preferred scale is returned.
{code}
I checked the MySQL which supports max precision 65 and max scale 30:
{code}
create table decimaltest (col1 decimal(65,14), col2 decimal(65, 14));
insert into decimaltest values 
(987654321001234567890123456789012345678901234567890.12345678901234, 
10000000000000.12345678901234);
select col1 * col2 from decimaltest
--
returns 
9876543210012345678901234567890123456789012345678901234567890000.000000000
{code}
It is hard to interpret this result, its precision is 73 ( > max 65) and scale 
is 9 (instead of 28). But its metadata in a JDBC application is decimal with 
precision 65 and scale 28.

> Issue in decimal multiplication
> -------------------------------
>
>                 Key: HIVE-14281
>                 URL: https://issues.apache.org/jira/browse/HIVE-14281
>             Project: Hive
>          Issue Type: Bug
>          Components: Types
>            Reporter: Chaoyu Tang
>            Assignee: Chaoyu Tang
>
> {code}
> CREATE TABLE test (a DECIMAL(38,18), b DECIMAL(38,18));
> INSERT OVERWRITE TABLE test VALUES (20, 20);
> SELECT a*b from test
> {code}
> The returned result is NULL (instead of 400)
> It is because Hive adds the scales from operands and the type for a*b is set 
> to decimal (38, 36). Hive could not handle this case properly (e.g. by 
> rounding)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to