[ https://issues.apache.org/jira/browse/HIVE-5022?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13754339#comment-13754339 ]
Gunther Hagleitner commented on HIVE-5022: ------------------------------------------ I tried to keep the data type standard compliant when I first implemented the HiveDecimal. I believe that the proposed patch isn't in accordance with the standard though. I might have misinterpreted it - happy to be corrected. >From what I remember: - Precision is always implementation specific - Scale is *only* implementation specific for division If an exact numeric value cannot be represented without rounding (in mult/add/sub) you're supposed to raise an error. I didn't do that because that seems bad in hive, so I returned "null" from the operation. Rounding implicitly for mult/add/sub seems to sort of defeat the purpose of having an exact numeric type. For division you can round or truncate but not loose any leading significant digits. (side note: div by zero is also supposed to error out, but in hive it returns null) So, one way to fix this problem would be to more aggressively round or truncate division. That way you will have more "room" for subsequent operations. Better yet, with HIVE-3976 we could have a default that's much smaller than the max and just round to the current scale of the dividend. This won't resolve this problem, but make it much less likely to occur. I also think that [~jdere] makes a good point. If we change the behavior in a non backwards compatible way, it would be really great to do that only once (i.e.: have HIVE-5022 and HIVE-3976 in the same release). In the meantime the "round manually" workaround should help. > Decimal Arithmetic generates NULL value > --------------------------------------- > > Key: HIVE-5022 > URL: https://issues.apache.org/jira/browse/HIVE-5022 > Project: Hive > Issue Type: Bug > Components: Types > Affects Versions: 0.11.0 > Environment: Hortonworks 1.3 running Hive 0.11.0.1.3.0.0-107 > Reporter: Kevin Soo Hoo > Assignee: Teddy Choi > Attachments: HIVE-5022.1.patch.txt, HIVE-5022.2.patch.txt, > HIVE-5022.3.patch.txt > > > When a decimal division is the first operation, the quotient cannot be > multiplied in a subsequent calculation. Instead, a NULL is returned. > The following yield NULL results: > select (cast (4.53 as decimal) / cast(25.86 as decimal)) * cast(0.087 as > decimal) from <tablename> limit 1; > select cast (4.53 as decimal) / cast(25.86 as decimal) * cast(0.087 as > decimal) from <tablename> limit 1; > If we move the multiplication operation to be first, then it will > successfully calculate the result. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira