Pig Shell Utility Commands

Let’s study about Pig Shell Utility Commands.

Shell Commands

There are two types of shell commands, they are.

  1. sh command
  2. 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.

sh Command

* 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”.

Syntax

grunt> sh shell command parameters

Example

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

bigdata.conf

nightly.conf

…..

grunt>

fs Command

* We can invoke any FsShell command within a Pig script or the Grunt shell.

Syntax

grunt> sh File System command parameters

Example

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

Utility Commands

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.

Example

grunt>clear

 2. Help Command

*Help command helps to list Pig commands or Pig properties.

Example

grunt>help

3. History Command

* History command is used to displays a list of statements executed so far in the Grunt shell.

Example

grunt>history

4. Set command

Set command is used to assigns values to keys used in Pig.

Example

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.

Example

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;

DUMP B;

grunt> exec firstscript.pig

(ram,20)

(roy,18)

(sitha,24)

(ali,18)

6. Kill Command

* Kill command is used to Kills a job based on a job id.

Example

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.

Example

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;

(ram,20)

(roy,18)

8. Quit Command

*Quit command is used to exit from the pig grunt shell.

Example

In this example the quit command exits the Pig grunt shell.

grunt> quit

Reference

https://pig.apache.org/docs/r0.9.1/cmds.html

“That’s all about the Pig Shell and Utility Commands, these are the basic commands for the pig Latin beginners”