gianm commented on a change in pull request #8566: Upgrade Calcite to 1.21
URL: https://github.com/apache/incubator-druid/pull/8566#discussion_r330152825
 
 

 ##########
 File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
 ##########
 @@ -1811,35 +1827,68 @@ public void testNullEmptyStringEquality() throws 
Exception
   @Test
   public void testEmptyStringEquality() throws Exception
   {
-    testQuery(
-        "SELECT COUNT(*)\n"
-        + "FROM druid.foo\n"
-        + "WHERE NULLIF(dim2, 'a') = ''",
-        ImmutableList.of(
-            Druids.newTimeseriesQueryBuilder()
-                  .dataSource(CalciteTests.DATASOURCE1)
-                  .intervals(querySegmentSpec(Filtration.eternity()))
-                  .granularity(Granularities.ALL)
-                  .filters(expressionFilter("case_searched((\"dim2\" == 'a'),"
-                                            + 
(NullHandling.replaceWithDefault() ? "1" : "0")
-                                            + ",(\"dim2\" == ''))"))
-                  .aggregators(aggregators(new CountAggregatorFactory("a0")))
-                  .context(TIMESERIES_CONTEXT_DEFAULT)
-                  .build()
-        ),
-        ImmutableList.of(
-            NullHandling.replaceWithDefault() ?
-            // Matches everything but "abc"
-            new Object[]{5L} :
-            // match only empty string
-            new Object[]{1L}
-        )
-    );
+    if (NullHandling.replaceWithDefault()) {
+      testQuery(
+          "SELECT COUNT(*)\n"
+          + "FROM druid.foo\n"
+          + "WHERE NULLIF(dim2, 'a') = ''",
+          ImmutableList.of(
+              Druids.newTimeseriesQueryBuilder()
+                    .dataSource(CalciteTests.DATASOURCE1)
+                    .intervals(querySegmentSpec(Filtration.eternity()))
+                    .granularity(Granularities.ALL)
+                    .filters(in("dim2", ImmutableList.of("", "a"), null))
+                    .aggregators(aggregators(new CountAggregatorFactory("a0")))
+                    .context(TIMESERIES_CONTEXT_DEFAULT)
+                    .build()
+          ),
+          ImmutableList.of(
+              // Matches everything but "abc"
+              new Object[]{5L}
+          )
+      );
+    } else {
+      testQuery(
+          "SELECT COUNT(*)\n"
+          + "FROM druid.foo\n"
+          + "WHERE NULLIF(dim2, 'a') = ''",
+          ImmutableList.of(
+              Druids.newTimeseriesQueryBuilder()
+                    .dataSource(CalciteTests.DATASOURCE1)
+                    .intervals(querySegmentSpec(Filtration.eternity()))
+                    .granularity(Granularities.ALL)
+                    .filters(selector("dim2", "", null))
+                    .aggregators(aggregators(new CountAggregatorFactory("a0")))
+                    .context(TIMESERIES_CONTEXT_DEFAULT)
+                    .build()
+          ),
+          ImmutableList.of(
+              // match only empty string
+              new Object[]{1L}
+          )
+      );
+    }
   }
 
   @Test
   public void testNullStringEquality() throws Exception
   {
+    testQuery(
+        "SELECT COUNT(*)\n"
+        + "FROM druid.foo\n"
+        + "WHERE NULLIF(dim2, 'a') = null",
+        ImmutableList.of(),
+        NullHandling.replaceWithDefault() ?
+        // Matches everything but "abc"
+        ImmutableList.of(new Object[]{0L}) :
+        // null is not eqaual to null or any other value
+        ImmutableList.of(new Object[]{0L})
+    );
+    /*
+    The SQL query in this test planned to the following Druid query in Calcite 
1.17.
 
 Review comment:
   What does the test case look like if `NULLIF(dim2, 'a') = NULL` is replaced 
with `NULLIF(dim2, 'a') IS NULL`? The new behavior seems like a valid 
optimization, since `<anything> = NULL` is false. We could update the SQL docs 
appropriately to point out that you should avoid `= NULL` and use `IS NULL` no 
matter what your null handling mode is.
   
   Btw, please don't include commented-out code.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to