datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

decimal division gives wrong answer

Open kmitchener opened this issue 3 years ago • 0 comments

Describe the bug A clear and concise description of what the bug is.

❯ select 10.1::decimal(5,1)/a from (values (1),(null)) as t(a);
+---------------------------+
| Float64(10.1) / t.a       |
+---------------------------+
| 10.0999999999999997902848 |
|                           |
+---------------------------+
2 rows in set. Query took 0.005 seconds.

Note also that the return type is correctly Decimal, it's just giving wrong results because it's using float internally to do the division.

❯ select arrow_typeof(10.1::decimal(5,1)/a) from (values (1),(null)) as t(a);
+----------------------------------+
| arrowtypeof(Float64(10.1) / t.a) |
+----------------------------------+
| Decimal128(26, 22)               |
| Decimal128(26, 22)               |
+----------------------------------+
2 rows in set. Query took 0.010 seconds.

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

This should return 10.1 and null.

Additional context Add any other context about the problem here.

kmitchener avatar Sep 16 '22 20:09 kmitchener