Slackbot
04/10/2023, 10:13 AMBibek Sahoo
04/10/2023, 11:28 AMJohn Kowtko
04/10/2023, 2:44 PMselect count(*), count(channel) from (select channel, count(*) numItems from wikipedia group by channel) where channel = 'x'
returns no records ... whereas this:
select count(*), count(channel) from (select channel from wikipedia) where channel = 'x'
Correctly returns zero counts.
I will log an engineering ticket for this.
Thanks. JohnLaksh Singla
04/11/2023, 3:41 AMGROUP BY.
This is consistent with the behaviour of SQL, if we explicitly mention a group by, i.e.
select count(*) from wikipedia where channel = 'x' group by 'dummy_key'
returns no records.
However if the GROUP BY clause is not present then we return the single record with count as 0 (which is where Druid’s behaviour is diverging from the expected SQL behaviour)
Can you raise a bug in Druid’s issues so that we can track it. Thanks! (https://github.com/apache/druid/issues/new?assignees=&labels=&template=other.md&title=)Vadim
04/11/2023, 6:00 AMgroup by clause then because you are using the count aggregator you still get an implicit group by () clause and it returns a single row. This is consistent with how other dbs behave. Here is MySQL for example http://sqlfiddle.com/#!9/a6c585/292295Vadim
04/11/2023, 6:06 AMcount in you query adding an aggregate function (count), by the rules of SQL, adds an implicit GROUP BY () that totally changes your query. In Q2 you do count(num) what are you trying to do? Because count(num) means give me a count of all rows where num is not null . Is that really what you want? Ususally when people use the count function they either do COUNT(*)- the count of rows or COUNT(DISTINCT x) the number of distinct x values.John Kowtko
04/11/2023, 11:49 AMselect count(*) from (select channel from wikipedia where channel = 'x') where channel = 'y'
Returns one record with zero (0) count.
select count(*) from (select channel, count(*) from wikipedia group by channel) where channel = 'y'
select count(*) from (select channel, count(*) from wikipedia where channel = 'x' group by channel)
Each of the above statements returns no records. In this case the native outer query type is "groupBy".
Interestingly:
select count(*) from (select channel, count(*) from wikipedia where channel = 'x' group by channel) where channel = 'y'
Also correctly returns one record with zero (0) count. The native outer query type is "scan" . So even though the subquery is a group by, the addition of the filter condition in the subquery avoids the translation issue for the outer query.Kanthraj Setty
05/09/2023, 9:44 AMJohn Kowtko
05/09/2023, 2:34 PMselect count(*) from (select channel, count(*) from wikipedia group by channel) where channel = 'y' LIMIT 10
select count(*) from (select channel, count(*) from wikipedia where channel = 'x' group by channel) LIMIT 10
with no luck.
Please do an Explain Plan on your query that is working and let us know what the top level "queryType" is.
Thanks. John