Interview Questions   Tutorials   Discussions   Programs   Videos   

Pig - Word Count program in PIG?




530
views
asked marvit January 26, 2015 10:53 PM  

Word Count program in PIG?


           

3 Answers



 
answered By marvit   0  

-- Load input from the file named Mary, and call the single

-- field in the record 'line'.

input = load 'mary' as (line);

-- TOKENIZE splits the line into a field for each word.

-- flatten will take the collection of records returned by

-- TOKENIZE and produce a separate record for each one, calling the single

-- field in the record word.

words = foreach input generate flatten(TOKENIZE(line)) as word;

-- Now group them together by each word.

grpd = group words by word;

-- Count them.

cntd = foreach grpd generate group, COUNT(words);

-- Print out the results.

dump cntd;

flag   
   add comment

 
answered By marvit   0  

A = load '/home/accure/shamshad/input.txt';

B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word;

C = group B by word;

D = foreach C generate COUNT(B), group; store D into './wordcount';

.

.

To run this pig script:

pig -x local /home/accure/shamshad/accure.pig

flag   
   add comment

 
answered By Experts-976   0  

Word Count program in PIG?

text= LOAD ‘text.txt’ USING TextLoader();
tokens=FOREACH text GENERATE FLATTEN (TOKENIZE($0)) as word;
wordcount = FOREACH (GROUP tokens BY word) GENERATE group as word, COUNT_STAR($1) as ct;
flag   
   add comment

Your answer

Join with account you already have

FF

Preview

 Write A Tutorials
Online-Classroom Classes
www.writeabc.com


  1 person following this question

  1 person following this tag

  Question tags

pig × 1

Asked 3 years and 19 days ago ago
Number of Views -530
Number of Answers -3
Last updated
2 years and 10 months ago ago

  Similar questions

Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert