Apache Pig Grunt Shell - Apache Pig

What are the shell and utility commands provided by the Grunt shell?

Once you invoke the Grunt shell, you can run your Pig scripts in the shell. You can also use some shell and utility commands provided by the Grunt shell.

Shell Commands

Shell commands in Apache Pig are mainly used to write Pig Latin scripts. Before that use sh and fs commands to invoke any shell command.

sh Command

Use sh command, we can invoke any shell commands from the Grunt shell. Using sh command from the Grunt shell, we cannot execute the commands that are a part of the shell environment (ex − cd).

Syntax

Here’s the syntax of sh command.

Example

To invoke the ls command of Linux shell from the Grunt shell use sh option as mentioned below. See below example that list out the files in the /pig/bin/ directory.

fs Command

Use fs command to invoke any FsShell commands from the Grunt shell.

Syntax

Here’s the syntax of fs command.

Example

Use ls command to invoke the HDFS from the Grunt shell using fs command. Here’s example.
Use fs command to invoke all the other file system shell commands from the Grunt shell.

Utility Commands

The Grunt shell offers asset of utility commands such as clear, help, history, quit, and set; and commands such as exec, kill, and run to control Pig from the Grunt shell. Here’s the decryption of the utility commands provided by the Grunt shell.

clear Command

The clear command is used to clear the screen of the Grunt shell.

Syntax

Use clear command to wipe out the screen of the grunt shell as mentioned below.

help Command

Use the help command to get the list of Pig commands or Pig properties.

Usage

You can get a list of Pig commands using the help command as mentioned below.

history Command

History command is useful to display the list of statements executed / used so far since the Grunt sell is invoked.

Usage

Assume we have executed three statements since opening the Grunt shell.
To get the below output use the history command.

set Command

The set command is used to show/assign values to keys used in Pig.

Usage

Use below command to set values with below mentioned keys.
Key
Description and values
default_parallel
You can set the number of reducers for a map job by passing any whole number as a value to this key.
debug
You can turn off or turn on the debugging freature in Pig by passing on/off to this key.
job.name
You can set the Job name to the required job by passing a string value to this key.
job.priority
You can set the job priority to a job by passing one of the following values to this key −
  • very_low
  • low
  • normal
  • high
  • very_high
stream.skippath
For streaming, you can set the path from where the data is not to be transferred, by passing the desired path in the form of a string to this key.

quit Command

To quit from the Grunt shell Quit command is used.

Usage

You can quit from the Grunt shell with below command.
Let’s have a look at the commands which you can control Apache Pig from the Grunt shell.

exec Command

Use exec command to execute Pig scripts from the Grunt shell.

Syntax

Here’s the syntax of the utility command exec.

Example

Let’s see that there is a file named student.txt in the /pig_data/ directory of HDFS with below content.
Student.txt
Now, have a script file named sample_script.pig in the /pig_data/ directory of HDFS with the below content.
Sample_script.pig
Let’s execute the above script from the Grunt shell using the exec command as mentioned below.

Output

The exec command is executed the script in the sample_script.pig. As mentioned in the script, it loads the student.txt file into Pig and gives you the result of the Dump operator displaying the mentioned content.

kill Command

Kill command is used to kill a job from the Grunt shell using this command.

Syntax

Here’s the syntax of the kill command.
Example
If you running Pig job having id Id_0055, you can kill it from the Grunt shell using the kill command, as mentioned below.
Run Command
You can run a Pig script from the Grunt shell using the run command
Syntax
Here’s the syntax of the run command.
Now, have a script file named sample_script.pig in the local file system with below mentioned content.
Sample_script.pig
Now, let’s run the above script from the Grunt shell by applying above run command.
Use the Dump operator to see the output of the script as mentioned below.
Note − The main difference between exec and the run command is that if we use run, the statements from the script are available in the command history.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Pig Topics