I have done mappings in the past using joins and mapping files too.

E.g. generate a file of mappings and load it as a relation, then join. A rather heavy weight solution though.

-Clay

On Wed, 14 Sep 2011, Eli Finkelshteyn wrote:

Hi,
I'd like to generate based on exclusive conditions (something like the CASE statement in SQL). An example:

Say I have data that looks like:

(a, 1)
(a, 2)
(b, 2)
(c, 1)
(d, 3)
(d, 4)

And I want to just convert each of the numbers to their written forms to get:

(a, one)
(a, two)
(b, two)
(c, one)
(d, three)
(d, four)

Would I need to write a udf for that, or is there some simple way to do it using cases? I know I can do a bunch of bidirectional generates one on top of the other to achieve this, like:

FOREACH rel GENERATE $0, (($1==1) ? 'one' : (($1 == 2) ? 'two' : (($1 == 3) ? 'three' : 'four')));

but that seems too messy. I'd appreciate any advice.

Thanks!
Eli



Reply via email to