We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
The text was updated successfully, but these errors were encountered:
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.
Postgres for reference:
postgres=# select cast(400420638.54 as decimal(32,16)) * cast(0.1 as decimal(32,16)); ?column? ------------------------------------------- 40042063.85400000000000000000000000000000 (1 row)
Sorry, something went wrong.
@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. 😁
Successfully merging a pull request may close this issue.
Describe the bug
Decimal multiplied by Float produces incorrect results
To Reproduce
This is fine:
This is not fine:
More info:
Expected behavior
Looks like type coercion needs to cast both sides to decimal.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: