-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix queries filtering for the same condition with both an IN and EQUALS to not return empty results #16597
Merged
abhishekagarwal87
merged 10 commits into
apache:master
from
kgyrtkirk:temp-fix-in-expansion
Jul 9, 2024
Merged
Fix queries filtering for the same condition with both an IN and EQUALS to not return empty results #16597
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a938bf
fix issue by running ReduceExpressionsRule early
kgyrtkirk 71274cb
add a different fix
kgyrtkirk 76f743e
undo
kgyrtkirk a3d3967
remove unrelated
kgyrtkirk 8a3c2b8
update msg
kgyrtkirk 8efd057
accept plan changes
kgyrtkirk d43bd5f
Merge remote-tracking branch 'apache/master' into temp-fix-in-expansion
kgyrtkirk 730b127
add not_equals
kgyrtkirk e0a1525
add test
kgyrtkirk c40736a
Revert "add test"
kgyrtkirk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
sql/src/main/java/org/apache/druid/sql/calcite/rule/FixIncorrectInExpansionTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.sql.calcite.rule; | ||
|
||
import org.apache.calcite.plan.RelOptRule; | ||
import org.apache.calcite.plan.RelOptRuleCall; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.rules.SubstitutionRule; | ||
import org.apache.calcite.rex.RexBuilder; | ||
import org.apache.calcite.rex.RexCall; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.calcite.rex.RexShuttle; | ||
import org.apache.calcite.rex.RexUtil; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
/** | ||
* Rewrites comparisions to avoid bug FIXME. | ||
* | ||
* Rewrites RexCall::VARCHAR = RexLiteral::CHAR to RexCall::VARCHAR = | ||
* RexLiteral::VARCHAR | ||
* | ||
* needed until CALCITE-6435 is fixed & released. | ||
*/ | ||
public class FixIncorrectInExpansionTypes extends RelOptRule implements SubstitutionRule | ||
{ | ||
public FixIncorrectInExpansionTypes() | ||
{ | ||
super(operand(RelNode.class, any())); | ||
Check notice Code scanning / CodeQL Deprecated method or constructor invocation Note
Invoking
RelOptRule.any Error loading related location Loading |
||
} | ||
|
||
@Override | ||
public void onMatch(RelOptRuleCall call) | ||
{ | ||
final RelNode oldNode = call.rel(0); | ||
final RewriteShuttle shuttle = new RewriteShuttle(oldNode.getCluster().getRexBuilder()); | ||
final RelNode newNode = oldNode.accept(shuttle); | ||
|
||
// noinspection ObjectEquality | ||
if (newNode != oldNode) { | ||
call.transformTo(newNode); | ||
call.getPlanner().prune(oldNode); | ||
} | ||
} | ||
|
||
private static class RewriteShuttle extends RexShuttle | ||
{ | ||
private final RexBuilder rexBuilder; | ||
|
||
public RewriteShuttle(RexBuilder rexBuilder) | ||
{ | ||
this.rexBuilder = rexBuilder; | ||
} | ||
|
||
@Override | ||
public RexNode visitCall(RexCall call) | ||
{ | ||
RexNode newNode = super.visitCall(call); | ||
if (newNode.getKind() == SqlKind.EQUALS || newNode.getKind() == SqlKind.NOT_EQUALS) { | ||
RexCall newCall = (RexCall) newNode; | ||
RexNode op0 = newCall.getOperands().get(0); | ||
RexNode op1 = newCall.getOperands().get(1); | ||
if (RexUtil.isLiteral(op1, false)) { | ||
|
||
if (op1.getType().getSqlTypeName() == SqlTypeName.CHAR | ||
&& op0.getType().getSqlTypeName() == SqlTypeName.VARCHAR) { | ||
|
||
RexNode newLiteral = rexBuilder.ensureType(op0.getType(), op1, true); | ||
return rexBuilder.makeCall( | ||
newCall.getOperator(), | ||
op0, | ||
newLiteral | ||
); | ||
} | ||
} | ||
} | ||
return newNode; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note