Getting Started PIG 1

Assalamualaykum wr br..:)

In this Post we are discussing the basics of Hadoop PIG. It is a language which is used to analyze the data in hadoop. It is also know as PIG LATIN. It is high level data processing language which possess rich data types and operators to perform various operations on Data in Hadoop.

To analyze data in hadoop we need to use PIG scripts and that should be executed in grunt

shell.Internally Apache converts these pig scripts into a series of mapreduce jobs and thus making programmers job easy. Architecture of PIG can be illustrated as below:


As we see there are various components involved in Apache PIG. Let us brief them.



It checks the syntax and semantics of scripts. Also involve in type checking and other miscellaneous checks. The output of the parser will be a DAG (directed acyclic graph), which represents the Pig Latin statements and logical operators.

In the DAG, the logical operators of the script are represented as the nodes and the data flows are represented as edges.


The logical plan (DAG) is passed to the logical optimizer, which carries out the logical optimizations such as projection and pushdown.


The compiler compiles the optimized logical plan into a series of MapReduce jobs.

Execution engine

Finally the MapReduce jobs are submitted to Hadoop in a sorted order. Finally, these MapReduce jobs are executed on Hadoop producing the desired results.

Pig Latin Data Model

The data model of Pig Latin is fully nested and it allows complex non-atomic datatypes such as map and tuple. Given below is the diagrammatical representation of Pig Latin’s data model.

Data Model


Any single value in Pig Latin, irrespective of their data, type is known as an Atom. It is stored as string and can be used as string and number. int, long, float, double, chararray, and bytearray are the atomic values of Pig. A piece of data or a simple atomic value is known as a field.

Example − ‘Aejaaz’ or ‘27’


A record that is formed by an ordered set of fields is known as a tuple, the fields can be of any type. A tuple is similar to a row in a table of RDBMS.

Example − (Aejaaz,27)


A bag is an unordered set of tuples. In other words, a collection of tuples (non-unique) is known as a bag. Each tuple can have any number of fields (flexible schema). A bag is represented by ‘{}’. It is similar to a table in RDBMS, but unlike a table in RDBMS, it is not necessary that every tuple contain the same number of fields or that the fields in the same position (column) have the same type.

Example − {(Aejaaz,27), (Mohammad, 45)}

A bag can be a field in a relation; in that context, it is known as inner bag.

Example − {Aejaaz,27, {008022008,,}}


A map (or data map) is a set of key-value pairs. The key needs to be of type chararray and should be unique. The value might be of any type. It is represented by ‘[]’

Example − [name#aejaaz, age#27]


A relation is a bag of tuples. The relations in Pig Latin are unordered (there is no guarantee that tuples are processed in any particular order).

Thats all for the Day..

Jazakallah khair..:)  Alhamdulliah.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s