xiedeyantu commented on code in PR #4452:
URL: https://github.com/apache/calcite/pull/4452#discussion_r2203658224
##########
mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoFilter.java:
##########
@@ -267,5 +290,14 @@ private void translateOp2(String op, String name,
RexLiteral right,
multimap.put(name, Pair.of(op, right));
}
}
+
+ /** Translates is null/is not null to $exists. */
+ private Void translatePostfix(RexCall call,
Review Comment:
Would it be better to change the method name to `translateUnary`? The format
can be referred to `translateBinary`.
##########
mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java:
##########
@@ -919,4 +919,77 @@ private static Consumer<List> mongoChecker(final String...
expected) {
"{$sort: {STATE: 1}}"))
.returns("STATE=ME; CITY=LEWISTON\nSTATE=VT; CITY=BRATTLEBORO\n");
}
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7079">[CALCITE-7079]
+ * Mongo adapter: unable to translate (A <> 'a' and A <> 'b') conditional
case </a>. */
+ @Test void testMultiNeFilterContition() {
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=ALTON; STATE=TX",
+ "CITY=AMES; STATE=IA",
+ "CITY=ANCHORAGE; STATE=AK");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "and city <> 'ALTON' order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\",
\"ALTON\"]}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=AMES; STATE=IA",
+ "CITY=ANCHORAGE; STATE=AK",
+ "CITY=BALTIMORE; STATE=MD");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "and state <> 'IA' and state <> 'TX' order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}, state:
{$nin: [\"IA\", \"TX\"]}}}",
Review Comment:
There is a missing $and in $match. I understand that other $and are
displayed translation. Although the default semantics is and, will this affect
the mixed use with other expressions?
##########
mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java:
##########
@@ -919,4 +919,77 @@ private static Consumer<List> mongoChecker(final String...
expected) {
"{$sort: {STATE: 1}}"))
.returns("STATE=ME; CITY=LEWISTON\nSTATE=VT; CITY=BRATTLEBORO\n");
}
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7079">[CALCITE-7079]
+ * Mongo adapter: unable to translate (A <> 'a' and A <> 'b') conditional
case </a>. */
+ @Test void testMultiNeFilterContition() {
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=ALTON; STATE=TX",
+ "CITY=AMES; STATE=IA",
+ "CITY=ANCHORAGE; STATE=AK");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "and city <> 'ALTON' order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\",
\"ALTON\"]}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=AMES; STATE=IA",
+ "CITY=ANCHORAGE; STATE=AK",
+ "CITY=BALTIMORE; STATE=MD");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "and state <> 'IA' and state <> 'TX' order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}, state:
{$nin: [\"IA\", \"TX\"]}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=ANCHORAGE; STATE=AK",
+ "CITY=BALTIMORE; STATE=MD",
+ "CITY=BANGOR; STATE=ME");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "or (state <> 'IA' and state <> 'TX') order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {$or: [{city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}},
{state: {$nin: [\"IA\", \"TX\"]}}]}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=ABERDEEN; STATE=SD",
+ "CITY=AIKEN; STATE=SC",
+ "CITY=ALTON; STATE=TX");
+
+ assertModel(MODEL)
+ .query("select city, state from zips where city <> 'ABERDEEN' and city
<> 'AIKEN' "
+ + "and state <> 'IA' order by city")
+ .limit(3)
+ .queryContains(
+ mongoChecker(
+ "{$match: {city: {$nin: [\"ABERDEEN\", \"AIKEN\"]}, state:
{$ne: \"IA\"}}}",
+ "{$project: {CITY: '$city', STATE: '$state'}}",
+ "{$sort: {CITY: 1}}"))
+ .returnsOrdered("CITY=ALTON; STATE=TX",
+ "CITY=ANCHORAGE; STATE=AK",
+ "CITY=BALTIMORE; STATE=MD");
+ }
+
+
Review Comment:
Please delete the extra blank lines
--
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]