You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "JiajunBernoulli (via GitHub)" <gi...@apache.org> on 2024/01/28 07:29:52 UTC

Re: [PR] [CALCITE-6214] Remove DISTINCT in aggregate function if field is unique [calcite]

JiajunBernoulli commented on code in PR #3641:
URL: https://github.com/apache/calcite/pull/3641#discussion_r1468774827


##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -6562,6 +6562,67 @@ private HepProgram getTransitiveProgram() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6214">[CALCITE-6214]
+   * Remove `DISTINCT` in `COUNT` if field is unique</a>. */
+  @Test void testAggregateDistinctRemove1() {
+    final String sql = ""
+        + "select count(distinct x) cnt\n"
+        + "from(\n"
+        + "   select distinct sal x from emp\n"
+        + ") t ";
+    sql(sql)
+        .withRule(CoreRules.AGGREGATE_REMOVE_DISTINCT)
+        .check();
+  }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6214">[CALCITE-6214]
+   * Remove `DISTINCT` in `COUNT` if field is unique</a>. */
+  @Test void testAggregateDistinctRemove2() {
+    final String sql = ""
+        + "select count(distinct x) cnt\n"
+        + "from(\n"
+        + "   select sal * 12 as x from emp"
+        + "   group by sal * 12\n"
+        + ") t ";
+    sql(sql)
+        .withRule(CoreRules.AGGREGATE_REMOVE_DISTINCT)
+        .check();
+  }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6214">[CALCITE-6214]
+   * Remove `DISTINCT` in `COUNT` if field is unique</a>. */
+  @Test void testAggregateDistinctRemove3() {

Review Comment:
   Yes, now we can handle other aggregate functions after new commits.



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org