How to use If Else in Wrangler Directives ?

1,231 views
Skip to first unread message

yogesh walia

unread,
Oct 10, 2018, 7:25:20 AM10/10/18
to cdap...@googlegroups.com
Hi,

How we can use if else conditions in wrangler recipe ?

Thanks

Sreevatsan Raman

unread,
Oct 10, 2018, 12:59:48 PM10/10/18
to cdap...@googlegroups.com
Yogesh, 

What's your use-case? 

If you'd like to set a column to a specific value based on condition, then the set columns directive allows you to specify a JEXL expression. As an example, if you'd like to add an  is_text column and set it to true based on call_type you can use a directive like the one below

set-column :is_text exp:{call_type == "SMS" ? true : false}

Let us know if this helps, or if you have any further questions, would be good to understand what you are trying to accomplish.

Thanks,
Sree

--
You received this message because you are subscribed to the Google Groups "CDAP User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cdap-user+...@googlegroups.com.
To post to this group, send email to cdap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cdap-user/CAPu8orSw0XsmeUHLqXMPQJWwoK7YZb2bxkLK2BQhXVO-OhXL-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

yogesh walia

unread,
Oct 11, 2018, 1:22:30 AM10/11/18
to cdap...@googlegroups.com
I need to call different recipes using if-else 

Nitin Motgi

unread,
Oct 11, 2018, 1:52:20 AM10/11/18
to cdap...@googlegroups.com
right now only grammar support is implemented. We have plans to add full support for execution of simple and nested if ... else ... 

As of now it’s not fully supported.

Nitin 


For more options, visit https://groups.google.com/d/optout.
--

Nitin Motgi

"We reap what we sow. We are the makers of
our own fate. The wind is blowing; those
vessels whose sails are unfurled catch it, and
go forward on their way, but those which have
their sails furled do not catch the wind. Is that
the fault of the wind?....... We make our own
destiny.”
                -- Swami Vivekananda

Luiz Rodrigo Tozzi

unread,
Mar 22, 2022, 9:30:54 PM3/22/22
to CDAP User
Hi Sree

I'm using CDAP 6.5.1 and 6.6.0 in GCP (Data Fusion) but everytime I try to use your set-column i get this error:

set-column :uc_origem exp:{project_name == “FOUNDATION” ? “2122” : “None”}
Error occurred : io.cdap.wrangler.parser.DirectivesLexer cannot be cast to org.antlr.v4.runtime.Parser

All columns are string and I'm using Wrangler 4.6.0

Any ideas?

Thanks

Sreevatsan Raman

unread,
Mar 22, 2022, 10:35:52 PM3/22/22
to cdap...@googlegroups.com
Can you make sure they are not null by adding a check before this directive?

Message has been deleted

Sreevatsan Raman

unread,
Mar 23, 2022, 1:40:05 PM3/23/22
to cdap...@googlegroups.com
Looks like a problem with quotes
set-column :uc_origem exp:{uc_origem == "FOUNDATION" ? "2122" : "None"}

I tried the above command and it works. 

On Wed, Mar 23, 2022 at 6:07 AM Luiz Rodrigo Tozzi <to...@ipnet.cloud> wrote:
Yes.

uc_origem is a new column but it gives the same error if I use an existing string not null column.

project_name is not null and also string

Reply all
Reply to author
Forward
0 new messages