-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
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
Incorrect float/double column comparison. #10686
Comments
I am planning to work on this. Thanks |
We should discuss if we want to do exact comparison between floating point numbers or fuzzy comparison. I'd suggest doing some research to see what is the behavior of the commonly used DBs. |
Also related to #10637 cc @elonazoulay |
I did a bit of analysis while going over the problem itself.
Actually, initially I thought it's a bug in H2 also and created an issue for this. Got nice explanation by the developer.
|
So seems all the DBs are doing exact match on Do you see the cast from double to float getting added during the query parsing? Why would it cast value from double to float, but not hoisting up to double? |
Yes. Apache Calcite supports implicit type conversion between float and double and hence depends on the left operand data type; the right operand is getting cast. So if the LHS is My initial solution approach is to remove/skip this casting function in case of comparison of float/double. What do you think about it? |
Losing precision might not be the root cause though. Even if we do float to double casting, the number won't match.
Which query is giving different result comparing to H2? |
Well, you are following the wrong order of casting. The problematic comparison involves casting from
We are ignoring the following queries in our test cases |
I see, so we actually expect it to cast from float to double and since we are converting from low precision to high precision it will return not equals. |
Comparison results on H2 DB
|
Thanks for taking time testing these comparisons, very interesting results! So Postgres and H2 have different behavior on float - big-decimal conversion, but double - big-decimal conversion is lossless in both DBs. |
+1; I'll try to implement this. Thanks |
We can close this one. Thanks |
FYI if you include |
We are ignoring a couple of numeric comparison queries between
float
anddouble
based columns, for exampleIt's failing because of the
cast
function fromdouble
tofloat
, hence losing precision and resulting incorrect output. The Apache calcite adds thecast
transformation function during query parsing. This issue tracks the implementation for correctly handling float/double comparison.The text was updated successfully, but these errors were encountered: