Pigs - separation, no default or if / else

Since there are no other or default pigs in a crossbreeding operation, what would be the most elegant way to do the following? I am not a big fan of copying paste code.

SPLIT rawish_data INTO good_rawish_data IF ( (uid > 0L) AND (value1 > 0) AND (value1 < 100) AND (value1 IS NOT NULL) AND (value2 > 0L) AND (value2 < 200L) AND (value3 >= 0) AND (value3 <= 300)), bad_rawish_data IF (NOT ( (uid > 0L) AND (value1 > 0) AND (value1 < 100) AND (value1 IS NOT NULL) AND (value2 > 0L) AND (value2 < 200L) AND (value3 >= 0) AND (value3 <= 300))); 

I would like to do something like

 SPLIT data INTO good_data IF ( (value > 0)), good_data_big_values IF ( (value > 100)), bad_data DEFAULT; 

Anyway, is something like this possible?

+6
source share
2 answers

It. Having selected SPLIT documents, you want to use OTHERWISE . For instance:

 SPLIT data INTO good_data IF ( (value > 0)), good_data_big_values IF ( (value > 100)), bad_data OTHERWISE; 

So you almost got it. :)

NOTE. SPLIT can put one line in both good_data and good_data_big_values if, for example, value was 150. I do not know if this is what you want, but you should know about it independently. This also means that bad_data will only contain strings where value is 0 or less.

+10
source

You can write UDF IsGood (), where all conditions will be checked. Then your pig just

 SPLIT data INTO good_data IF (IsGood(data)) good_data_big_values IF (IsGood(data) AND value > 100)), bad_data IF (NOT IsGood(data)) ; 

Another option might be to use macro

+2
source

Source: https://habr.com/ru/post/954239/


All Articles