jon-wei commented on a change in pull request #8566: Upgrade Calcite to 1.21
URL: https://github.com/apache/incubator-druid/pull/8566#discussion_r348863925
##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -1937,35 +1953,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(),
Review comment:
No native Druid query is actually generated for this, the filter would never
be true and Calcite just returns a count of 0
----------------------------------------------------------------
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]