suibianwanwank commented on PR #4218:
URL: https://github.com/apache/calcite/pull/4218#issuecomment-2692325081
@xuzifu666 @asolimando I added the following test to DruidAdapter2IT and it
returned the same results before and after the change. I agree with @xuzifu666
that the original logic here is incorrect, but I'm not too familiar with the
code here, and I don't know why the test wasn't affected.
```
@Test void testNotInFilter() {
final String sql = "select \"state_province\", \"city\",\n"
+ " \"product_name\", \"quarter\"\n"
+ "from \"foodmart\"\n"
+ "where \"product_name\" = 'High Top Dried Mushrooms'\n"
+ "and \"quarter\" not in ('Q1', 'Q4')\n"
+ "and \"state_province\" = 'WA'";
final String druidQuery = "{'queryType':'scan',"
+ "'dataSource':'foodmart',"
+
"'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+ "'filter':{'type':'and','fields':["
+ "{'type':'selector','dimension':'product_name','value':'High Top
Dried Mushrooms'},"
+
"{'type':'not','field':{'type':'selector','dimension':'quarter','value':'Q1'}},"
+
"{'type':'not','field':{'type':'selector','dimension':'quarter','value':'Q4'}},"
+ "{'type':'selector','dimension':'state_province','value':'WA'}]},"
+ "'columns':['state_province','city','product_name','quarter'],"
+ "'resultFormat':'compactedList'}";
final String explain = "PLAN=EnumerableInterpreter\n"
+ " DruidQuery(table=[[foodmart, foodmart]], "
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
+ "filter=[AND("
+ "=($3, 'High Top Dried Mushrooms'), "
+ "SEARCH($87, Sarg[(-∞..'Q1':VARCHAR),
('Q1':VARCHAR..'Q4':VARCHAR), ('Q4':VARCHAR..+∞)]:VARCHAR), "
+ "=($30, 'WA'))], "
+ "projects=[[$30, $29, $3, $87]])\n";
sql(sql)
.queryContains(new DruidChecker(druidQuery))
.explainContains(explain)
.returnsUnordered(
"state_province=WA; city=Bremerton; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Everett; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Kirkland; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Lynnwood; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Olympia; product_name=High Top Dried
Mushrooms; quarter=Q2",
"state_province=WA; city=Port Orchard; product_name=High Top
Dried Mushrooms; quarter=Q3",
"state_province=WA; city=Puyallup; product_name=High Top Dried
Mushrooms; quarter=Q2",
"state_province=WA; city=Puyallup; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Spokane; product_name=High Top Dried
Mushrooms; quarter=Q2",
"state_province=WA; city=Spokane; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Spokane; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Tacoma; product_name=High Top Dried
Mushrooms; quarter=Q2",
"state_province=WA; city=Yakima; product_name=High Top Dried
Mushrooms; quarter=Q2",
"state_province=WA; city=Yakima; product_name=High Top Dried
Mushrooms; quarter=Q3",
"state_province=WA; city=Yakima; product_name=High Top Dried
Mushrooms; quarter=Q2");
}
@Test void testNotInFilter1() {
final String sql = "select \"state_province\", \"city\",\n"
+ " \"product_name\", \"quarter\"\n"
+ "from \"foodmart\"\n"
+ "where \"product_name\" = 'High Top Dried Mushrooms'\n"
+ "and \"quarter\" in ('Q1', 'Q4')\n"
+ "and \"state_province\" = 'WA'";
final String druidQuery = "{'queryType':'scan',"
+ "'dataSource':'foodmart',"
+
"'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+ "'filter':{'type':'and','fields':["
+ "{'type':'selector','dimension':'product_name','value':'High Top
Dried Mushrooms'},"
+
"{'type':'or','fields':[{'type':'selector','dimension':'quarter','value':'Q1'},{'type':'selector','dimension':'quarter','value':'Q4'}]},"
+ "{'type':'selector','dimension':'state_province','value':'WA'}]},"
+ "'columns':['state_province','city','product_name','quarter'],"
+ "'resultFormat':'compactedList'}";
final String explain = "PLAN=EnumerableInterpreter\n"
+ " DruidQuery(table=[[foodmart, foodmart]], "
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
+ "filter=[AND("
+ "=($3, 'High Top Dried Mushrooms'), "
+ "SEARCH($87, Sarg['Q1':VARCHAR, 'Q4':VARCHAR]:VARCHAR), "
+ "=($30, 'WA'))], "
+ "projects=[[$30, $29, $3, $87]])\n";
sql(sql)
.queryContains(new DruidChecker(druidQuery))
.explainContains(explain)
.returnsUnordered(
"state_province=WA; city=Bremerton; product_name=High Top Dried
Mushrooms; quarter=Q4",
"state_province=WA; city=Olympia; product_name=High Top Dried
Mushrooms; quarter=Q4",
"state_province=WA; city=Port Orchard; product_name=High Top
Dried Mushrooms; quarter=Q1",
"state_province=WA; city=Puyallup; product_name=High Top Dried
Mushrooms; quarter=Q1",
"state_province=WA; city=Spokane; product_name=High Top Dried
Mushrooms; quarter=Q1",
"state_province=WA; city=Spokane; product_name=High Top Dried
Mushrooms; quarter=Q4",
"state_province=WA; city=Tacoma; product_name=High Top Dried
Mushrooms; quarter=Q4",
"state_province=WA; city=Yakima; product_name=High Top Dried
Mushrooms; quarter=Q4");
}
```
change:
```
---
a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidJsonFilter.java
+++
b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidJsonFilter.java
@@ -294,7 +294,7 @@ abstract class DruidJsonFilter implements DruidJson {
if (columnName == null) {
return null;
}
- if (e.getKind() != SqlKind.NOT_IN) {
+ if (e.getKind() == SqlKind.DRUID_IN) {
return new DruidJsonFilter.JsonInFilter(columnName,
listBuilder.build(), extractionFunction);
} else {
return toNotDruidFilter(
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]