You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by soniya B <so...@gmail.com> on 2013/10/18 08:34:24 UTC

convert rows to columns in Pig

Hi,

How to convert rows to columns in pig latin?

example:

input file

A   100     3
B   200     4
C   400     6

required output

A        B        C

100     200    400

Re: convert rows to columns in Pig

Posted by yonghu <yo...@gmail.com>.
I don't think you can solve this problem by just using pig default
operators. You need to write you own program.


On Sat, Oct 19, 2013 at 5:37 AM, soniya B <so...@gmail.com> wrote:

> any one can guide me on this problem?
>
>
> On Fri, Oct 18, 2013 at 1:15 PM, soniya B <so...@gmail.com>
> wrote:
>
> > I think it will work for to change columns to rows. I am looking to
> change
> > rows to columns.
> >
> >
> > On Fri, Oct 18, 2013 at 12:14 PM, ajay kumar <ajaysanagapati@gmail.com
> >wrote:
> >
> >> try this,
> >>
> >> A = load 'input';
> >> B = foreach A generate FLATTEN(TOBAG(*));
> >>
> >>
> >> On Fri, Oct 18, 2013 at 12:04 PM, soniya B <so...@gmail.com>
> >> wrote:
> >>
> >> > Hi,
> >> >
> >> > How to convert rows to columns in pig latin?
> >> >
> >> > example:
> >> >
> >> > input file
> >> >
> >> > A   100     3
> >> > B   200     4
> >> > C   400     6
> >> >
> >> > required output
> >> >
> >> > A        B        C
> >> >
> >> > 100     200    400
> >> >
> >>
> >>
> >>
> >> --
> >> *Thanks & Regards,*
> >> *S. Ajay Kumar
> >> +91-9966159106*
> >>
> >
> >
>

Re: convert rows to columns in Pig

Posted by Alan Gates <ga...@hortonworks.com>.
I think the following will do what you want:

A = load 'input';
B = group A all;
C = foreach B generate flatten(BagToTuple(A));

Note that this will collect all records into one bag and produce one output record.  That won't scale well, and may not be what you want.

Alan.

On Oct 18, 2013, at 8:37 PM, soniya B wrote:

> any one can guide me on this problem?
> 
> 
> On Fri, Oct 18, 2013 at 1:15 PM, soniya B <so...@gmail.com> wrote:
> 
>> I think it will work for to change columns to rows. I am looking to change
>> rows to columns.
>> 
>> 
>> On Fri, Oct 18, 2013 at 12:14 PM, ajay kumar <aj...@gmail.com>wrote:
>> 
>>> try this,
>>> 
>>> A = load 'input';
>>> B = foreach A generate FLATTEN(TOBAG(*));
>>> 
>>> 
>>> On Fri, Oct 18, 2013 at 12:04 PM, soniya B <so...@gmail.com>
>>> wrote:
>>> 
>>>> Hi,
>>>> 
>>>> How to convert rows to columns in pig latin?
>>>> 
>>>> example:
>>>> 
>>>> input file
>>>> 
>>>> A   100     3
>>>> B   200     4
>>>> C   400     6
>>>> 
>>>> required output
>>>> 
>>>> A        B        C
>>>> 
>>>> 100     200    400
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> *Thanks & Regards,*
>>> *S. Ajay Kumar
>>> +91-9966159106*
>>> 
>> 
>> 


-- 
CONFIDENTIALITY NOTICE
NOTICE: This message is intended for the use of the individual or entity to 
which it is addressed and may contain information that is confidential, 
privileged and exempt from disclosure under applicable law. If the reader 
of this message is not the intended recipient, you are hereby notified that 
any printing, copying, dissemination, distribution, disclosure or 
forwarding of this communication is strictly prohibited. If you have 
received this communication in error, please contact the sender immediately 
and delete it from your system. Thank You.

Re: convert rows to columns in Pig

Posted by soniya B <so...@gmail.com>.
any one can guide me on this problem?


On Fri, Oct 18, 2013 at 1:15 PM, soniya B <so...@gmail.com> wrote:

> I think it will work for to change columns to rows. I am looking to change
> rows to columns.
>
>
> On Fri, Oct 18, 2013 at 12:14 PM, ajay kumar <aj...@gmail.com>wrote:
>
>> try this,
>>
>> A = load 'input';
>> B = foreach A generate FLATTEN(TOBAG(*));
>>
>>
>> On Fri, Oct 18, 2013 at 12:04 PM, soniya B <so...@gmail.com>
>> wrote:
>>
>> > Hi,
>> >
>> > How to convert rows to columns in pig latin?
>> >
>> > example:
>> >
>> > input file
>> >
>> > A   100     3
>> > B   200     4
>> > C   400     6
>> >
>> > required output
>> >
>> > A        B        C
>> >
>> > 100     200    400
>> >
>>
>>
>>
>> --
>> *Thanks & Regards,*
>> *S. Ajay Kumar
>> +91-9966159106*
>>
>
>

Re: convert rows to columns in Pig

Posted by soniya B <so...@gmail.com>.
I think it will work for to change columns to rows. I am looking to change
rows to columns.


On Fri, Oct 18, 2013 at 12:14 PM, ajay kumar <aj...@gmail.com>wrote:

> try this,
>
> A = load 'input';
> B = foreach A generate FLATTEN(TOBAG(*));
>
>
> On Fri, Oct 18, 2013 at 12:04 PM, soniya B <so...@gmail.com>
> wrote:
>
> > Hi,
> >
> > How to convert rows to columns in pig latin?
> >
> > example:
> >
> > input file
> >
> > A   100     3
> > B   200     4
> > C   400     6
> >
> > required output
> >
> > A        B        C
> >
> > 100     200    400
> >
>
>
>
> --
> *Thanks & Regards,*
> *S. Ajay Kumar
> +91-9966159106*
>

Re: convert rows to columns in Pig

Posted by ajay kumar <aj...@gmail.com>.
try this,

A = load 'input';
B = foreach A generate FLATTEN(TOBAG(*));


On Fri, Oct 18, 2013 at 12:04 PM, soniya B <so...@gmail.com> wrote:

> Hi,
>
> How to convert rows to columns in pig latin?
>
> example:
>
> input file
>
> A   100     3
> B   200     4
> C   400     6
>
> required output
>
> A        B        C
>
> 100     200    400
>



-- 
*Thanks & Regards,*
*S. Ajay Kumar
+91-9966159106*