Slackbot
07/05/2023, 10:43 AMBibek Sahoo
07/05/2023, 11:26 AMAhmad Qasem
07/05/2023, 1:32 PMorg.apache.druid.query.aggregation.AggregatorFactoryJohn Kowtko
07/05/2023, 1:44 PMselect count (distinct flags) from wikipedia
with tmp as (
select flags, count(*) from wikipedia where flags is not null and flags != '' group by flags
)
select count(*) from tmp
Both statements above should produce the same result. The second statement generates a native GroupBy query type.Ahmad Qasem
07/05/2023, 1:48 PMAhmad Qasem
07/05/2023, 1:49 PMSELECT user_id, COUNT(DISTINCT devices) devices_count, SUM(clicks)
FROM my_table
WHERE __time >= '2023-06-26T01:03:41.177-04:00' AND __time <= '2023-06-27T01:03:41.177-04:00' AND user_id = '123'
GROUP BY user_id
but I couldn’t find a way to apply it in druid using either aggregations nor post aggregationsJohn Kowtko
07/05/2023, 2:16 PMwith tmp as (
select user_id, devices, sum(clicks) sum_clicks
from my_table
where __time >= '2023-06-26T01:03:41.177-04:00'
and __time <= '2023-06-27T01:03:41.177-04:00'
and user_id = '123'
group by user_id, devices
)
select user_id, count(*) devices_count, sum(sum_clicks) sum_clicks
from tmp
group by user_id
You can always do an Explain Plan on the above query to get the native query version.
You may have to filter out NULL and/or EMPTY device names from the CTE in order to not include those as distinct values.Ahmad Qasem
07/05/2023, 2:22 PMGian Merlino
07/06/2023, 7:18 AMCOUNT(DISTINCT <expr>) is planned as a count on top of a subquery to compute the distinct valuesGian Merlino
07/06/2023, 7:18 AMAhmad Qasem
07/06/2023, 8:52 AMJohn Kowtko
07/06/2023, 12:14 PMAhmad Qasem
07/06/2023, 12:17 PMGian Merlino
07/06/2023, 2:02 PM