Fix queries filtering for the same condition with both an IN and EQUALS to not return empty results#16597
Conversation
| { | ||
| public FixIncorrectInExpansionTypes() | ||
| { | ||
| super(operand(RelNode.class, any())); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| { | ||
| public FixIncorrectInExpansionTypes() | ||
| { | ||
| super(operand(RelNode.class, any())); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
gianm
left a comment
There was a problem hiding this comment.
I suspect the PR description is not accurate; it says:
current approach is to run the ReduceExpressionRule early to get rid of the problematic issue
but that does not seem to be what is happening. Could you please clarify what the bug is and how we're fixing it?
| public RexNode visitCall(RexCall call) | ||
| { | ||
| RexNode newNode = super.visitCall(call); | ||
| if (newNode.getKind() == SqlKind.EQUALS) { |
There was a problem hiding this comment.
is this really only needed for EQUALS? what about NOT_EQUALS, GREATER_THAN, etc? what about other kinds of operations on strings?
There was a problem hiding this comment.
to raise the current error:
- a literal generated by that part in
SqlToRelfor anINexpression orNOT IN - a comparision with
equalsshould happen inRexSimplify
I've tried a few queries with not in ; and they were not able to trigger the issue.
but I've added NOT_EQUALS as there might be some twisted case just in case...
thank you for noticing this! that would have been the easiest to fix it - however it had some adverse effects; so I've decided to write a custom rule instead. (updated the desc) |
sreemanamala
left a comment
There was a problem hiding this comment.
Looks good. Quick qsn - Can we have the sqlToRelWorkaroundProgram to have multiple temporary rules in case if we need similar rules rather than a singleton list or we need to have a new Program?
|
thank you @sreemanamala for taking a look; I expect this |
abhishekagarwal87
left a comment
There was a problem hiding this comment.
Tried a few queries. All passed. PR lgtm.
…LS to not return empty results (apache#16597) temp fix until CALCITE-6435 gets fixed (released&upgraded to) added a custom rule (FixIncorrectInExpansionTypes) to fix-up types of the affected literals added a testcase which will alert on upgrade
FixIncorrectInExpansionTypes) to fix-up types of the affected literalsRelease note
Queries filtering for the same string value with both an IN expression and an = filter may have been incorrectly returned an empty resultset.
This PR has: