You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Mohit Anchlia <mo...@gmail.com> on 2012/09/26 00:47:10 UTC

Line split

I have a input files that I need to split into multiple rows but with the
same key. For example:

1,a\nb\n
2,a\nc\n

After the split this looks like:

1,a
1,b
2,a
2,c

Is this possible without writing an exec method?

Re: Line split

Posted by Cheolsoo Park <ch...@cloudera.com>.
Hi,

a = load 'input.txt' using PigStorage(',') as (id:int,list:chararray);
b = foreach a generate id, FLATTEN(TOKENIZE(list,'\\n'));

This returns what you want:

(1,a)
(1,b)
(2,a)
(2,c)

Thanks,
Cheolsoo

On Tue, Sep 25, 2012 at 3:47 PM, Mohit Anchlia <mo...@gmail.com>wrote:

> I have a input files that I need to split into multiple rows but with the
> same key. For example:
>
> 1,a\nb\n
> 2,a\nc\n
>
> After the split this looks like:
>
> 1,a
> 1,b
> 2,a
> 2,c
>
> Is this possible without writing an exec method?
>