Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Describe the bug
Decimal multiplied by Float produces incorrect results
To Reproduce
This is fine:
❯ select cast(400420638.54 as decimal(12,2));
+-----------------------+
| Float64(400420638.54) |
+-----------------------+
| 400420638.54 |
+-----------------------+
1 row in set. Query took 0.000 seconds.
This is not fine:
❯ select cast(400420638.54 as decimal(12,2)) * 1.0;
+------------------------------------+
| Float64(400420638.54) * Float64(1) |
+------------------------------------+
| 10377.38413171004264709 |
+------------------------------------+
1 row in set. Query took 0.000 seconds.
More info:
❯ explain select cast(400420638.54 as decimal(12,2)) * 1.0;
+---------------+--------------------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+--------------------------------------------------------------------------------------------------+
| logical_plan | Projection: Decimal128(Some(1037738413171004264709),38,17) AS Float64(400420638.54) * Float64(1) |
| | EmptyRelation |
| physical_plan | ProjectionExec: expr=[Some(1037738413171004264709),38,17 as Float64(400420638.54) * Float64(1)] |
| | EmptyExec: produce_one_row=true |
| | |
+---------------+--------------------------------------------------------------------------------------------------+
2 rows in set. Query took 0.001 seconds.
Expected behavior
Looks like type coercion needs to cast both sides to decimal.
❯ select cast(400420638.54 as decimal(12,2)) * cast(1.0 as decimal(12,2));
+------------------------------------+
| Float64(400420638.54) * Float64(1) |
+------------------------------------+
| 400420638.54 |
+------------------------------------+
1 row in set. Query took 0.000 seconds.
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
andygrove commentedon Oct 30, 2022
Here is some more odd behavior:
Postgres for reference:
andygrove commentedon Oct 30, 2022
@liukun4515 are you familiar with this area of code?
liukun4515 commentedon Nov 2, 2022
@andygrove
sorry for the later reply.
Recently, I am busy for some internal business.
Will be back soon. 😁