xiedeyantu commented on code in PR #4774:
URL: https://github.com/apache/calcite/pull/4774#discussion_r2761782247


##########
mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoProject.java:
##########
@@ -76,7 +76,9 @@ public MongoProject(RelOptCluster cluster, RelTraitSet 
traitSet,
             MongoRules.mongoFieldNames(getInput().getRowType()));
     final List<String> items = new ArrayList<>();
     for (Pair<RexNode, String> pair : getNamedProjects()) {
-      final String name = pair.right;
+      final String name = pair.right.startsWith("$f")
+          ? "_" + pair.right.substring(2)

Review Comment:
   It seems there's no test result for this line of code.



##########
mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java:
##########
@@ -1046,4 +1046,51 @@ private static Consumer<List> mongoChecker(final 
String... expected) {
                 "{$group:{_id:{},_0:{$min:'$POP'}}}",
                 "{$project:{EXPR$0:{$abs:['$_0']}}}"));
   }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7404";>[CALCITE-7404]
+   * Incorrect Field Alias in MongoDB project Stage</a>. */
+  @Test void testAggFunctionMinFilter() {
+    assertModel(MODEL)
+        .query("select min(pop>5000) as pop_result from zips")
+        .queryContains(
+            mongoChecker(
+                "{$project:{_0:{$gt:['$pop',{$literal:5000}]}}}",
+                "{$group:{_id: {},POP_RESULT:{$min:'$_0'}}}"))
+        .returns("POP_RESULT=false\n");
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7404";>[CALCITE-7404]
+   * Incorrect Field Alias in MongoDB project Stage</a>. */
+  @Test void testAliasNameOrderBy() {
+    assertModel(MODEL)
+        .query("select pop as pop_a from zips"
+            + " order by pop_a")
+        .limit(3)
+        .queryContains(
+            mongoChecker(
+                "{$project:{POP_A:'$pop'}}",
+                "{$sort: {POP_A: 1}}"))
+        .returnsOrdered("POP_A=21",
+            "POP_A=17522",
+            "POP_A=22576");
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7404";>[CALCITE-7404]
+   * Incorrect Field Alias in MongoDB project Stage</a>. */
+  @Test void testNameOrderBy() {

Review Comment:
   The same as above?



-- 
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]

Reply via email to