-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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