kfaraz commented on a change in pull request #12182:
URL: https://github.com/apache/druid/pull/12182#discussion_r789379051



##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -2143,6 +2143,93 @@ public void testHavingOnExactCountDistinct() throws 
Exception
     );
   }
 
+  @Test
+  public void testExactCountDistinctWithFilter() throws Exception
+  {
+
+    final String sqlQuery = "SELECT COUNT(DISTINCT foo.dim1) FILTER(WHERE 
foo.cnt = 1), SUM(foo.cnt) FROM druid.foo";
+    // When useApproximateCountDistinct=true and 
useGroupingSetForExactDistinct=false, planning fails due
+    // to a bug in the Calcite's rule (AggregateExpandDistinctAggregatesRule)
+    try {
+      testQuery(
+          PLANNER_CONFIG_NO_HLL, // Enable exact count distinct
+          sqlQuery,
+          CalciteTests.REGULAR_USER_AUTH_RESULT,
+          ImmutableList.of(),
+          ImmutableList.of()
+      );
+    }
+    catch (RuntimeException e) {
+      Assert.assertTrue(e.getMessage().contains("Error while applying rule 
AggregateExpandDistinctAggregatesRule"));

Review comment:
       If the above try does not throw an exception, this assertion will never 
be made.
   You could
   - either break the positive and negative cases into two separate methods and 
use expected exception
   - or verify the positive case first and then verify the negative case
   
   In both of the above, you could use `assertThrows` or use `@Test(expected = 
...)`.
   You could also use try catch but the test should ensure that the exception 
is always thrown.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to