Grunt : It is a shell, where we have been writing our Pig scripts. Generally production code will be written in a separate file. But while writing we want to test our scripts with test data, hence we will be using Grunt shell for prototyping our script.
 
Remember :
  • It provides Tab completion of commands (Not file name as in shell scripts)
  • Ctrl+D will help you to come out of Grunt 
Dump and Store : Pig Latin will not execute scripts until it sees Dump or Store command , as we have done in our example.
 
Step 1 : Now load the file stored in hdfs (Space separated file)
input  = LOAD 'hadoopexam.txt' AS (f1:chararray);

DUMP input;
(I am learning Pig Using HadoopExam)
(I am learning Pig Using HadoopExam)
(I am learning Pig Using HadoopExam)
 
Step 2 : flatten the words in each line
wordsInEachLine = FOREACH input GENERATE flatten(TOKENIZE(f1)) as word;
DUMP wordsInEachLine;
 
Accessing HDFS : You can use hdfs commands inside Grunt shell as below
> fs -ls
 
Accessing local shell
> sh ls