[CALCITE-3433] EQUALS operator between date/timestamp types returns false if the type is nullable#1540
[CALCITE-3433] EQUALS operator between date/timestamp types returns false if the type is nullable#1540DonnyZone wants to merge 1 commit intoapache:masterfrom
Conversation
| Primitive boxPrimitive1 = Primitive.ofBox(expression1.getType()); | ||
| if (boxPrimitive0 != null && boxPrimitive1 != null | ||
| && !isConstantNullExpression(expression0) | ||
| && !isConstantNullExpression(expression1)) { |
There was a problem hiding this comment.
I think we should move this logic into [1]
[1]
There was a problem hiding this comment.
Do you mean that we should keep the evaluation logic and codegen logic as same?
There was a problem hiding this comment.
No, i misunderstood, sorry for that ~
|
There is already a For this case, the generated code may like this |
|
@yanlin-Lynn Thanks for good advice! We can fall back to call backupMethodName in SqlFunctions. |
aba2b0c to
5ff35e8
Compare
|
@danny0405 @yanlin-Lynn, I update the fix. Could you take a look when you have time? |
| if (EQUALS_OPERATORS.contains(op) | ||
| && boxPrimitive0 != null && boxPrimitive1 != null | ||
| && !isConstantNullExpression(expressions.get(0)) | ||
| && !isConstantNullExpression(expressions.get(1))) { |
There was a problem hiding this comment.
How about if one operand is Long and another is Integer but with the same value ?
There was a problem hiding this comment.
In RexImpTable, when defining BinaryImplementor, there is a harmonize function called to ensure that operands have identical type.
There was a problem hiding this comment.
Well, the defineBinary indeed is with harmonize as true, thanks for the explanation.
| } | ||
| ConstantExpression ce = (ConstantExpression) expression; | ||
| return ce.value == null; | ||
| } |
There was a problem hiding this comment.
I think isConstantNullExpression is unnecessary, it seems null value is processed in
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java#L1083.
You can check again.
There was a problem hiding this comment.
@yanlin-Lynn Yes, we can remove this check. Comments addressed, thanks!
…alse if the type is nullable (DonnyZone)
5ff35e8 to
c63883e
Compare
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540 Change-Id: I2acb25a189c607f03e8aab61ad3a592f7ce61550
…alse if the type is nullable (DonnyZone) When checking equals or not-equals on two primitive boxing classes (i.e. Long x, Long y), we should fall back to call `SqlFunctions.eq(x, y)` and `SqlFunctions.ne(x, y)`, rather than `x == y`. close apache#1540 Change-Id: I2acb25a189c607f03e8aab61ad3a592f7ce61550
Currently,
BinaryExpressiongenerates allEqual/NotEqualoperation as "=="/"!=".However, when comparing two primitive boxing classes, we may get wrong result, such as the example described in CLACITE-3433.
This PR adopts
Objects.equalsto handle this problem.