3
votes

My requirement is to generate multiple lines of output by using single line of input in pig scripting. What are the possible solutions?

1
One solution is that I should use UDFs or streaming functionality of PIG to do this.Ashish

1 Answers

7
votes

The idea is to convert you input line into a bag and then flatten it. Here could be 2 cases:

Reading text:

txt = load '/pig_fun/input/text.txt' using TextLoader();
words = foreach txt generate TOKENIZE($0);
pivoted = foreach words generate FLATTEN($0);
dump pivoted;

Input:

My requirement is to generate multiple lines of output by using single line of input in pig scripting.
What are the possible solutions?

OUTPUT:

(My)
(requirement)
(is)
(to)
(generate)
(multiple)
(lines)
(of)
(output)
(by)
(using)
(single)
(line)
(of)
(input)
(in)
(pig)
(scripting.)
(What)
(are)
(the)
(possible)
(solutions?)

Reading columns and then pivoting them see Pivot table with Apache Pig