How to do postaggregation metrics based on dimensions?

First of all: sorry if the answer might be obvious but I could not find a solution to achieve the following:

Let’s say we have

  • 3 dimensions (A_dim,B_dim,C_dim)

  • 4 metrics (A_met, B_met, C_met, D_met)

What we want:

  • SUM(A_met)

  • SUM(B_met)

  • (B_dim == x) ? (C_met + 1) : (C_met + SUM(A_met))

  • all grouped by A_dim,B_dim,C_dim

The “if else” is (of course) the tricky part, I know how to achieve this with sql but had no luck so far doing this kind of query in druid…

Should I somehow add B_dim also as a metric?

Any hint or example query would be greatly appreciated :slight_smile:


You could do the if/else now using a JavaScript aggregator (see for instructions and caveats).

And in the next version of Druid, you’ll be able to do it in Druid SQL using a standard CASE statement.

I am aware about the js aggregation and that's totally fine (doesn't need to be sql) but the question was rather how to combine metrics with dimensions in such a function, as far as I found out it's only possible to combine metrics in postaggegation js functions, no?