[CALCITE-6617] TypeCoercion is not applied correctly to comparisons - #3998
Conversation
|
@arkanovicz can you please check if this solves the issue you have reported? |
| RelDataType commonType; | ||
| if (SqlTypeUtil.sameNamedType(type1, type2)) { | ||
| // First check when one of the types is a string (see JavaDoc on cmmonTypeForBinaryComparison) | ||
| commonType = commonTypeForBinaryComparison(type1, type2); |
There was a problem hiding this comment.
prior to this change, coercion would not insert casts when comparing say int to double, because they didn't have the same type name. that was a bug.
| if (SqlTypeUtil.sameNamedType(type1, type2)) { | ||
| // First check when one of the types is a string (see JavaDoc on cmmonTypeForBinaryComparison) | ||
| commonType = commonTypeForBinaryComparison(type1, type2); | ||
| if (commonType == null && SqlTypeUtil.isComparable(type1, type2)) { |
There was a problem hiding this comment.
Why do we need to judge this SqlTypeUtil.isComparable(type1, type2)?
There was a problem hiding this comment.
This is about comparison operators, you'd think that if 2 values with types are comparable, then the values can be compared by being cast to a common type.
5a7bada to
6a787d0
Compare
NobiGo
left a comment
There was a problem hiding this comment.
Strangely, we need to change the numbers written in SQL, which may cause compatibility issues with previous versions.
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
|
You don't need to modify any SQL programs, but the unparsed programs may look different. |
Additional tests in cast.iq (Julian Hyde) Close apache#3998 Signed-off-by: Mihai Budiu <mbudiu@feldera.com>



TypeCoercion was handling incorrectly most comparisons, leaving them without casts even when the two operands had different types. After this PR comparisons should always compare operands of the same type.