Lin Ma
Lin Ma

Reputation: 10159

how to manually construct a tuple in Apache Pig on Hadoop

I have a text file and each line is a string, I want to construct one tuple from all the strings in the text file. Wondering how to implement in Pig?

thanks in advance, Lin

Upvotes: 0

Views: 99

Answers (1)

Murali Rao
Murali Rao

Reputation: 2287

@Lin Ma : If the objective is to have each line as a field in Tuple then, we can make use of the below snippet.

Input :

line1 data ....
line2 data ....
line3 data ....
lineN data .....

Pig Script :

text_data = LOAD 'text_data.txt'  USING  PigStorage('\n') AS (line_data:chararray);
text_data_gpr_all = GROUP text_data ALL;
required_data = FOREACH text_data_gpr_all GENERATE BagToTuple(text_data.line_data) ;
DUMP required_data;

Output :

((line1 data ....,line2 data ....,line3 data ....,lineN data .....))

Ref : http://pig.apache.org/docs/r0.11.0/api/org/apache/pig/builtin/BagToTuple.html

Upvotes: 2

Related Questions