You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/30 15:54:18 UTC

[GitHub] [arrow-datafusion] andygrove opened a new issue, #4035: Decimal multiplied by Float produces incorrect results

andygrove opened a new issue, #4035:
URL: https://github.com/apache/arrow-datafusion/issues/4035

   **Describe the bug**
   Decimal multiplied by Float produces incorrect results
   
   **To Reproduce**
   
   Using benchmark data, define with decimal field:
   
   ```
   ❯ create external table partsupp (ps_partkey int, ps_suppkey int, ps_availqty int, ps_supplycost decimal(12,2), ps_comment varchar) stored as csv with delimiter '|' location '../benchmarks/data/partsupp.csv';
   
   0 rows in set. Query took 0.000 seconds.
   ❯ select
       sum(ps_supplycost)
       from
       partsupp;
   +-----------------------------+
   | SUM(partsupp.ps_supplycost) |
   +-----------------------------+
   | 400420638.54                |
   +-----------------------------+
   1 row in set. Query took 0.224 seconds.
   ❯ select
       sum(ps_supplycost) * 1.1
       from
       partsupp;
   +--------------------------------------------+
   | SUM(partsupp.ps_supplycost) * Float64(1.1) |
   +--------------------------------------------+
   | 1206.65153731696031007                     |
   +--------------------------------------------+
   1 row in set. Query took 0.246 seconds.
   ```
   
   The result here is clearly wrong.
   
   It works fine if the column is defined as float rather than decimal.
   
   ```
   ❯ create external table partsupp (ps_partkey int, ps_suppkey int, ps_availqty int, ps_supplycost float, ps_comment varchar) stored as csv with delimiter '|' location '../benchmarks/data/partsupp.csv';
   
   0 rows in set. Query took 0.000 seconds.
   ❯ select
       sum(ps_supplycost)
       from
       partsupp;
   +-----------------------------+
   | SUM(partsupp.ps_supplycost) |
   +-----------------------------+
   | 400420638.53610957          |
   +-----------------------------+
   1 row in set. Query took 0.183 seconds.
   ❯ select
       sum(ps_supplycost) * 1.1
       from
       partsupp;
   +--------------------------------------------+
   | SUM(partsupp.ps_supplycost) * Float64(1.1) |
   +--------------------------------------------+
   | 440462702.38972056                         |
   +--------------------------------------------+
   1 row in set. Query took 0.174 seconds.
   ```
   
   **Expected behavior**
   A clear and concise description of what you expected to happen.
   
   **Additional context**
   Add any other context about the problem here.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] Dandandan closed issue #4035: Decimal multiplied by Float produces incorrect results

Posted by GitBox <gi...@apache.org>.
Dandandan closed issue #4035: Decimal multiplied by Float produces incorrect results
URL: https://github.com/apache/arrow-datafusion/issues/4035


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] andygrove commented on issue #4035: Decimal multiplied by Float produces incorrect results

Posted by GitBox <gi...@apache.org>.
andygrove commented on issue #4035:
URL: https://github.com/apache/arrow-datafusion/issues/4035#issuecomment-1296292958

   @liukun4515 are you familiar with this area of code?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] andygrove commented on issue #4035: Decimal multiplied by Float produces incorrect results

Posted by GitBox <gi...@apache.org>.
andygrove commented on issue #4035:
URL: https://github.com/apache/arrow-datafusion/issues/4035#issuecomment-1296292768

   Here is some more odd behavior:
   
   ```
   ❯ select cast(400420638.54 as decimal(32,15)) * cast(0.1 as decimal(32,15));
   +--------------------------------------+
   | Float64(400420638.54) * Float64(0.1) |
   +--------------------------------------+
   | 40042063.854000005133107             |
   +--------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ```
   
   ```
   ❯ select cast(400420638.54 as decimal(32,16)) * cast(0.1 as decimal(32,16));
   +--------------------------------------+
   | Float64(400420638.54) * Float64(0.1) |
   +--------------------------------------+
   | -791820.1765126158512068             |
   +--------------------------------------+
   1 row in set. Query took 0.000 seconds.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] liukun4515 commented on issue #4035: Decimal multiplied by Float produces incorrect results

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on issue #4035:
URL: https://github.com/apache/arrow-datafusion/issues/4035#issuecomment-1299927948

   > @liukun4515 are you familiar with this area of code?
   
   > are you familiar with this area of code?
   
   @andygrove 
   
   sorry for the later reply. 
   
   Recently, I am busy for some internal business.
   Will be back soon. 😁


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org