<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Decimal Data Type returning slightly incorrect results when dividing decimals in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52473#M57558</link>
    <description>&lt;P&gt;I should clarify that DECIMAL_V2 is currently just an experimental flag and the behaviour may change. Likely its behaviour will be in flux until all the subtasks of &lt;A href="https://issues.apache.org/jira/browse/IMPALA-4924" target="_blank"&gt;https://issues.apache.org/jira/browse/IMPALA-4924&lt;/A&gt; are finished.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2017 21:00:48 GMT</pubDate>
    <dc:creator>Tim Armstrong</dc:creator>
    <dc:date>2017-03-21T21:00:48Z</dc:date>
    <item>
      <title>Decimal Data Type returning slightly incorrect results when dividing decimals</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52451#M57556</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anybody ran into problems when dividing decimal types in Impala?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We run the following query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;select a.var1, a.var2, a.var3,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;a.var1 * (1 + (a.var2- a.var3) /1200 ) as problem_statement,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;150 * (1 + (5.56 - 0.36) /1200) as raw_values&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;select * from table_a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;) a,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(select * from table_b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;) b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Our results are:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;a.var1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a.var2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a.var3 &amp;nbsp; &amp;nbsp; &amp;nbsp; problem_statement &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raw_values&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;150 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5.56 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.36 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 150.6499999995 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 150.65&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Even though the problem_statement and raw_value are the same select statement, they get back slightly different values. Because we round some of our variables and call them later in the query, this error is altering our entire query results. The correct value is being returned by the raw_results query.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I will note that the data types for problem_statement and raw_value are different. One is a decimal data type and the other is a double&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;lv_hmbs_participation_bal &amp;nbsp; &amp;nbsp; &amp;nbsp; decimal(12,2) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;grosscoupon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;decimal(10,6) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;lv_hmbs_servicing_fee &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;decimal(10,6)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;problem_statement_no_round decimal(30,13)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;raw_values &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Has anybody else ran into this issue?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:17:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52451#M57556</guid>
      <dc:creator>mjrice04</dc:creator>
      <dc:date>2022-09-16T11:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal Data Type returning slightly incorrect results when dividing decimals</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52457#M57557</link>
      <description>&lt;P&gt;I think there are a couple of things going on. You may be running into some of the rounding issues covered by &lt;A href="https://issues.apache.org/jira/browse/IMPALA-4810" target="_blank"&gt;https://issues.apache.org/jira/browse/IMPALA-4810&lt;/A&gt;. In Impala 2.9 there will be a DECIMAL_V2 query option that will switch to a decimal mode that addresses some of these problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expression (5.56 - 0.36) / 1200 also is treated as DOUBLE rather than DECIMAL, which is confusing and we plan to fix &lt;A href="https://issues.apache.org/jira/browse/IMPALA-3437" target="_blank"&gt;https://issues.apache.org/jira/browse/IMPALA-3437&lt;/A&gt;. If you change 1200 to 1200.0 you'll actually get a DECIMAL result. You can use the typeof() function to inspect the result types of functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[localhost:21000] &amp;gt; select typeof((5.56 - 0.36)  / 1200), typeof((5.56 - 0.36) / 1200.0);
+------------------------------+--------------------------------+
| typeof((5.56 - 0.36) / 1200) | typeof((5.56 - 0.36) / 1200.0) |
+------------------------------+--------------------------------+
| DOUBLE                       | DECIMAL(11,8)                  |
+------------------------------+--------------------------------+
Fetched 1 row(s) in 0.01s&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 18:22:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52457#M57557</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2017-03-21T18:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal Data Type returning slightly incorrect results when dividing decimals</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52473#M57558</link>
      <description>&lt;P&gt;I should clarify that DECIMAL_V2 is currently just an experimental flag and the behaviour may change. Likely its behaviour will be in flux until all the subtasks of &lt;A href="https://issues.apache.org/jira/browse/IMPALA-4924" target="_blank"&gt;https://issues.apache.org/jira/browse/IMPALA-4924&lt;/A&gt; are finished.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 21:00:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52473#M57558</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2017-03-21T21:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal Data Type returning slightly incorrect results when dividing decimals</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52504#M57559</link>
      <description>&lt;P&gt;Hi TIm, thank you for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently running CDH 5.8.3 and Impala 2.6. Will Impala 2.9 be included in CDH 5.11?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So it looks like my options are to either use the double type instead of the decimal type, or use 1200.0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to also note I am getting this issue in Hive as well as Impala&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 13:23:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52504#M57559</guid>
      <dc:creator>mjrice04</dc:creator>
      <dc:date>2017-03-22T13:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal Data Type returning slightly incorrect results when dividing decimals</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52584#M57560</link>
      <description>&lt;P&gt;Hi Tim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to resond and say that we were running into the issues that you brought up, I will also note that changing our double values of 1200 to 1200.0 does seem to remedy that particular problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 16:10:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Decimal-Data-Type-returning-slightly-incorrect-results-when/m-p/52584#M57560</guid>
      <dc:creator>mjrice04</dc:creator>
      <dc:date>2017-03-23T16:10:22Z</dc:date>
    </item>
  </channel>
</rss>

