julianhyde commented on code in PR #3641:
URL: https://github.com/apache/calcite/pull/3641#discussion_r1461070613
##########
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 = ""
Review Comment:
Can you add at least one test where the outer query has a `GROUP BY`? The
following query should benefit from the simplification:
```
SELECT deptno, COUNT(DISTINCT sal),
FROM (
SELECT DISTINCT deptno, sal
FROM emp)
GROUP BY deptno
```
Note that `sal` is not distinct but it is distinct for each `deptno`
(because `(deptno, sal)` is a key).
--
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]