run and exec utility command difference in pig


Apache Pig Utility command gives two similar type of commands run and exec to execute pig script on grunt shell, I am looking the difference only run gives flexibility to developer some interaction with grunt shell where as exec just follow the instruction and don't accept any other input, my question is towards the use case where exactly it will be useful to use run over exec command.

Going through the apache pig documentation -, where a very high level detail provided for these two command.

grunt> cat myscript.pig
b = ORDER a BY name;
c = LIMIT b 10;

grunt> a = LOAD 'student' AS (name, age, gpa);

grunt> run myscript.pig

grunt> d = LIMIT c 3;

grunt> DUMP d;

grunt> cat myscript.pig
a = LOAD 'student' AS (name, age, gpa);
b = LIMIT a 3;

grunt> exec myscript.pig

3 Answer(s)


Hi Nitesh,

You are right, the major difference between the run and exec in pig is:
run - 1. every store triggers execution.
        2.The statements from the script are put into the command history and all the aliases defined in the script can be referenced in subsequent statements after the run command has completed

exec - 1. No store trigger execute.
         2. The statements from the script are available in command history. No reference is available after command.

When you have some task to execute on pig regulary, exec is preferrable. While when you have to execute certain commands before executing some final commands, you preferred run.

Hope this helps.



Thanks Abhijit this helped me to understand.