ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19375

PIg: how to create a categorical variable?

I am using PIG 0.12 on a large dataset, and I need to create a categorical variable such as

FOREACH mydata GENERATE category = 1 IF condition1
                        category = 2 IF condition2
                        category = 3 IF condition3

That syntax does not work. Is it possible to do that in Pig?

Thanks!

Upvotes: 0

Views: 94

Answers (1)

54l3d
54l3d

Reputation: 3973

Depending to the complication of the condition, there is some solution here:

bincond:

(condition ? value_if_true : value_if_false) 

case:

X = FOREACH A GENERATE f2, (
  CASE f2 % 2
    WHEN 0 THEN 'even'
    WHEN 1 THEN 'odd'
  END
);

udf:

FOREACH mydata GENERATE category_udf(field_2b_checked)

Upvotes: 1

Related Questions