apache pig - Using Pig conditional operator to implement or? -


let's have table f, consisting of following columns:

a, b 0, 1 0, 0 0, 0 0, 1 1, 0 1, 1 

i want create new column, c, equal | b.

i've tried following:

f = foreach f generate a, b, ((a or b) == 1) ? 1 : 0 c; 

but receive following error:

error org.apache.pig.tools.grunt.grunt - error 1200: pig script failed parse: noviablealtexception(91@[]) 

the or condition construction not correct, can try this?

f = foreach f generate a, b, (((a==1) or (b==1))?1:0) c; 

sample example:
input:

0,1 0,0 0,0 0,1 1,0 1,1 

pigscript:

a = load 'input' using pigstorage(',') (a:int,b:int); b = foreach generate a, b, (((a==1) or (b==1))?1:0) c; dump b; 

output:

(0,1,1) (0,0,0) (0,0,0) (0,1,1) (1,0,1) (1,1,1) 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -