问题
I have a structure like
{A, {1,2,3}}
{B, {4,5,6}}
What I want is
{A, "1|2|3"}
{B, "4|5|6"}
- I looked at CONCAT operator but that will not help me achieve what I wanted.
回答1:
This is most easily achieved with a Python UDF.
myudfs.py
#!/usr/bin/python
@outputSchema('concated: string')
def concat_bag(BAG):
return '|'.join([ str(i) for i in BAG ])
It can be used like:
Register 'myudfs.py' using jython as myfuncs;
-- Schema of A is: A:{ T:(letter: chararray, B_of_nums: {num: int}) }
B = FOREACH A GENERATE TOTUPLE(T.letter, myfuncs.concat_bag(T.B_of_nums)) ;
-- The output should be:
-- (A, 1|2|3)
-- (B, 1|2|3)
来源:https://stackoverflow.com/questions/21104792/in-pig-how-to-concatenate-all-items-in-bag