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

3,327 views
Skip to first unread message

Ehiz Ize

unread,
Jun 5, 2017, 2:13:16 AM6/5/17
to Druid User
Hi,

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

SELECT

CASE WHEN one = '1' then '11'
ELSE '22' END

can this be achieved on druid.

Thanks in advance

Gian Merlino

unread,
Jun 6, 2017, 2:44:06 AM6/6/17
to druid...@googlegroups.com
You can achieve something like this using a "javascript" extractionFn, see: http://druid.io/docs/latest/querying/dimensionspecs.html, 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.

Gian

--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+unsubscribe@googlegroups.com.
To post to this group, send email to druid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/druid-user/6c9f377a-b0df-4742-9fb8-b8fe6e225dc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ehiz Ize

unread,
Jun 6, 2017, 8:06:54 AM6/6/17
to Druid User
Thanks Gian :)


On Tuesday, 6 June 2017 12:14:06 UTC+5:30, Gian Merlino wrote:
You can achieve something like this using a "javascript" extractionFn, see: http://druid.io/docs/latest/querying/dimensionspecs.html, 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.

Gian

On Sun, Jun 4, 2017 at 11:13 PM, Ehiz Ize <ehizv...@gmail.com> wrote:
Hi,

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

SELECT

CASE WHEN one = '1' then '11'
ELSE '22' END

can this be achieved on druid.

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+...@googlegroups.com.

Robert Ervin

unread,
Mar 21, 2018, 8:04:38 PM3/21/18
to Druid User
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.

Thanks,
- Robert

Gian Merlino

unread,
Mar 21, 2018, 8:36:50 PM3/21/18
to druid...@googlegroups.com
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: http://druid.io/docs/latest/misc/math-expr.html and we will be linking it into the rest of the docs soon.

Gian

--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+unsubscribe@googlegroups.com.
To post to this group, send email to druid...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages