2

I'm currently learning the hadoop framework and the pig latin language. Now I've a problem.

I've got a data-set with the following format:

"long a, long b, char c, char d"

Now I want to read this data-sets with pig. That's no problem with the load and PigStoarage funktion..

bla = load 'data/examples/test' as (a:long, b:long, c:chararray, d:chararray);

My next step is, that I want to compare a with b on each line. If a is greater than b it's okay. If b is greater than a, I wan't to switch a with b, so that the higher value is always the first value of my data set...

Is this possible? In Java I can do this with a simple "compareTo"...

sorry for my bad english :-)

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59

1 Answers1

2
blb = FOREACH bla GENERATE ((a < b) ? b : a), ((a < b) ? a : b), c, d;

This operator in Pig is called bincond. The first one says, if a is less than b, then output b. The second one says, if a is less than b, then output a. Notice that when a is greater than b, it outputs the opposite.

Donald Miner
  • 38,889
  • 8
  • 95
  • 118