Grokbase Groups Pig user June 2011
FAQ
I'm having trouble trying to flatten a bag to a tuple of int's in Pig,

e.g.

{(12),(4),(7),(190)}

to:

(12,4,7,190)

It seems like it should be trivial to do, but not quite sure how to do it.
Can this by done with inbuilt Pig
commands or do i need a custom UDF or an exec?

Many thanks,
Jon.

Search Discussions

  • Aniket Mokashi at Jun 22, 2011 at 10:04 pm
    Hi,

    I think UDF BagToTuple should do it for you.
    From some old email thread, I find (I think you will have to change
    getBagField to get etc)--

    public class BagToTuple extends EvalFunc<Tuple>{
    @Override
    public void exec(Tuple input, Tuple output) throws IOException{
    DataBag bag = input.getBagField(0);
    Iterator<Tuple> iter = bag.content();
    while (iter.hasNext()){
    output.appendField(iter.next().getAtomField(0));
    }
    }
    }

    Thanks,
    Aniket
    On Wed, Jun 22, 2011 at 9:28 AM, Jonathan Holloway wrote:

    I'm having trouble trying to flatten a bag to a tuple of int's in Pig,

    e.g.

    {(12),(4),(7),(190)}

    to:

    (12,4,7,190)

    It seems like it should be trivial to do, but not quite sure how to do it.
    Can this by done with inbuilt Pig
    commands or do i need a custom UDF or an exec?

    Many thanks,
    Jon.


    --
    "...:::Aniket:::... Quetzalco@tl"

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriespig, hadoop
postedJun 22, '11 at 4:29p
activeJun 22, '11 at 10:04p
posts2
users2
websitepig.apache.org

People

Translate

site design / logo © 2021 Grokbase