Pig Programming - Create Your First Apache Pig Script - Edureka
Pig Programming - Create Your First Apache Pig Script - Edureka
COURSES »
Webinars
Blog »
Interview Questions
As is the case with scripts in other programming languages such as SQL, Unix Shell, etc., Pig scripts
are used to execute a set of Apache Pig commands collectively. This helps in reducing the time and
effort invested in writing and executing each command manually while doing the Pig
programming. This blog (Pig Programming: Create Your First Apache Pig script) is a step by step
guide to help you create your first Apache Pig script.
Local Mode: In ‘local mode’, you can execute the pig script in local file system. In this case you
don’t need to store the data in Hadoop HDFS file system, instead you can work with the data stored
in local file system itself.
HDFS Mode: In ‘HDFS mode’, the data needs to be stored in HDFS file system and you can process
the data with the help of pig script.
This command will create a ‘sample.pig’ file inside the home directory of cloudera user.
Let us say our task is to read data from a data file and to display the required contents on the as
output.
To process this data using Pig, this file should be present in Apache Hadoop HDFS.
Use the following command:
DUMP B;
The first command loads the file ‘information.txt’ into variable A with indirect schema (FName,
LName, MobileNo, City, Profession).
The second command loads the required data from variable A to variable B.
The third line displays the content of variable B on the terminal/console.
To execute the pig script in HDFS mode, run the following command:
Command: pig sample.pig
Got a question for us? Mention them in the comments section and we will get back to you.
Related Posts:
Like 46 Tweet 10 5