You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by "Katukuri, Jay" <jk...@ebay.com> on 2010/06/10 01:57:36 UTC

if - else logic in Pig

Hello,
How do we implement the following "if-else" SQL logic in Pig ?

Select column-1, column-2,  if(column-3 >=200, 20, column-3) column_new_3
>From table-1

In the above SQL , if the value of a field (column-3) is greater than threshold (200), it uses some other value(20). Else, it uses the original value itself.

Thanks,
Jay

RE: if - else logic in Pig

Posted by Richard Ding <rd...@yahoo-inc.com>.
Use Pig Latin:

Result = foreach table-1 generate column-1, column-2, ((column-3 >= 200) ? 20 : column-3); 

Thanks,
-Richard

-----Original Message-----
From: Katukuri, Jay [mailto:jkatukuri@ebay.com] 
Sent: Wednesday, June 09, 2010 4:58 PM
To: pig-user@hadoop.apache.org
Subject: if - else logic in Pig

Hello,
How do we implement the following "if-else" SQL logic in Pig ?

Select column-1, column-2,  if(column-3 >=200, 20, column-3) column_new_3
>From table-1

In the above SQL , if the value of a field (column-3) is greater than threshold (200), it uses some other value(20). Else, it uses the original value itself.

Thanks,
Jay