Pig Shell Utility Commands
Let’s study about Pig Shell Utility Commands.
There are two types of shell commands, they are.
- sh command
- fs command
* In Apache pig Grunt shell is mainly used to write Pig Latin scripts.we can invoke any shell commands using sh and fs.
* We can invoke any sh shell command within a Pig script or the Grunt shell.
Note: The sh commands used to run real programs. Commands such as cd are not programs but part of the shell environment and as such commands cannot be executed, unless the user invokes the shell explicitly, like “bash cd”.
|grunt> sh shell command parameters|
In this example we are listing out all the files in /pig/bin/ directory by invoking ls command of linux shell from the grunt shell.
|grunt> sh ls|
* We can invoke any FsShell command within a Pig script or the Grunt shell.
|grunt> sh File System command parameters|
In this example we are listing out all the files in the HDFS root directory by invoking ls command of HDFS from the grunt shell.
|grunt> fs -ls|
In this example using fs command we are creating directory.
|grunt> fs -mkdir newdata|
Here by using fs command we copy the files.
|grunt> fs -copyFromLocal file-x file-y|
Let’s study the pig Utility commands one by one.
1. Clear Command
* clear command is used to clear the content of the screen of the Grunt shell.
2. Help Command
*Help command helps to list Pig commands or Pig properties.
3. History Command
* History command is used to displays a list of statements executed so far in the Grunt shell.
4. Set command
* Set command is used to assigns values to keys used in Pig.
In this example key value pairs are set at the command line.
|grunt> SET debug ‘on’|
grunt> SET job.name ‘my firstjob’
> SET default_parallel 100
5. exec command
* Using exec command we can run a Pig script without the interaction between the script and the Grunt shell.
In this example firstscript.pig script is displayed and run using exec command.
|grunt> cat firstscript.pig|
A = LOAD ’employee’ AS (name, age);
B = LIMIT a 4;
grunt> exec firstscript.pig
6. Kill Command
* Kill command is used to Kills a job based on a job id.
In this example the job with id job_0007 is killed.
|grunt> kill job_0007|
7. Run command
*Run command is used to run a Pig script that can interact with the Grunt shell.
Note: Both run and exec commands are useful for debugging because it support to modify a Pig script in an editor and then rerun the script in the Grunt shell without leaving the shell.
In this example the script interacts with the results of commands issued via the Grunt shell.
|grunt> cat myfirstscript.pig|
a = LOAD ’employee’ AS (name, age);
b = ORDER a BY name;
c = LIMIT b 10;
grunt> a = LOAD ’employee’ AS (name, age);
grunt> run myfirstscript.pig
> d = LIMIT c 2;
> DUMP d;
8. Quit Command
*Quit command is used to exit from the pig grunt shell.
In this example the quit command exits the Pig grunt shell.
“That’s all about the Pig Shell and Utility Commands, these are the basic commands for the pig Latin beginners”