Skip to content
Advertisement

SUM aggregation do not work on empty subqueries with DRUID

Assuming I am executing the following two queries on Druid:

I tried to combine both counts in one single query with a sum aggregation like the following:

And it works well UNLESS one of the two counts returns 0 rows.

In that case I receive a Query returned no data message and I don’t have any final result from the SUM query even if one of the two subqueries returned some results.

How can I solve this?

Advertisement

Answer

Use conditional aggregation with CASE expressions:

Note that, in case there is a field_1 value that is common in both groups of field_2 = 10 and field_2 = 11, it will be counted in both groups, just like your code.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement