Perform "IF", "ELSE" or "CASE" Statement in Druid


I’m new to Druid and i would like to know how to perform a CASE or IF/ELSE Statement in my Select Query,


CASE WHEN one = ‘1’ then ‘11’

can this be achieved on druid.

Thanks in advance

You can achieve something like this using a “javascript” extractionFn, see:, although it’s limited to working on a single input column at a time.

Future versions of Druid will include an expression language that can express this case/when, among other things, without the need for javascript.

Thanks Gian :slight_smile:

Hi Gian,

I know Druid has gone under some changes lately to support Druid SQL. I see there are case statements allowed in that, and wondered if any of those changes allowed for similar case statements in non-sql.


  • Robert

Hi Robert,

They do, and generally will plan into native Druid queries using filtered aggregators or using the (not yet fully documented) expression feature. You can check it out by writing a Druid SQL query and prepending “EXPLAIN PLAN FOR” to the front to see the native Druid query that gets run. Look for “case_searched” expressions. The language is documented here: and we will be linking it into the rest of the docs soon.