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

Killing Job Inside Grunt shell : By using kill command , we can kill the MapReduce jobs. Usually as soon as you submit your pig scripts it will print job_id as well. And you can use kill command and job_id together to kill the job as below.
> kill {job_id}

exec command : Inside Grunt shell , you can use exec command to run Pig script.

run commandInside Grunt shell , you can use run command to run Pig script.

Difference between run and exec : run command runs the Pig Latin script in the same shell in which run command is executed.Hence, all the aliases defined inside the scripts will be available in same shell. But this is not the case with the exec command.