This message was deleted.
# general
s
This message was deleted.
b
Do you get any error, Could you share screen shot for both the output?
j
You are right:
Copy code
select count(*), count(channel) from (select channel, count(*) numItems from wikipedia group by channel) where channel = 'x'
returns no records ... whereas this:
Copy code
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. John
1
l
I think this happens because Druid returns no buckets if don’t match anything for
GROUP BY
. This is consistent with the behaviour of SQL, if we explicitly mention a group by, i.e.
Copy code
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=)
v
if you remove the
group 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/292295
Kanthraj regarding your original question you said "i just added the count()" you do not "just" add
count
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.
j
I have experimented with this a bit. The problem as I see it happens under some conditions when your subquery is a group by, the native SQL also types the outer query as a "groupBy", which results in "select count(*) with group by" behavior, i.e. no rows returned. The outer query here is not a group by, regardless of what the type of subquery is. I ran some more variations to see what would happen:
Copy code
select count(*) from (select channel from wikipedia where channel = 'x') where channel = 'y'
Returns one record with zero (0) count.
Copy code
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:
Copy code
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.
k
i found a work around for this count(*) not getting displayed i just added a limit at the end i'm getting the result. This is not a correct solution but a workaround i found all of a sudden.
j
Hmmm ... I just tried these:
Copy code
select 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