Pig Data Types

Pig Data Types have the similarity with java data types.
We use Pig Data Types with Pig Relations, Before we learn the Data types we need to understand the following concepts.

Pig Relation:

Pig relations are like a table in sql.
Example : Employee = Load ‘EmployeeData.xls’ using PigStorage(‘,’) as (name:chararray, age:int, salary:float);
Here Employee is a Relation.


Pig Bag:

 is a collation of tuples, it starts and ends with curly braces { }, Bag in Pig can be either Inner Bag (a bag within another bag) or Outer Bag.
 Example : {(Jack, Jill, JavaChain.com), {(Connecticut, Newjersey, Newyork)}}

Here {(Connecticut,Newjersey, Newyork)} is a inner Bag and the remaining lies with outer bag.


Pig Tuple:

is a set of elements with in open and close parentheses.

Example :  from the above example, following are the tuples.
(Jack, Jill, Javachin.com)
(Connecticut, Newjersey, Newyork)


Pig Data types can be  classified as

1.Basic Pig Data Types :

Data Types Description How can we use use Pig Data Types?
int It is a Signed 32-bit integer value Int can hold any integer value Ex: 23
long It is a Signed 64-bit integer value long can hold any Long value i.e bigger than Integer value and it can be displayed as 23L
float It is a 32-bit floating point value Float can be represented as  4.5F or 4.5.5f or 4.5e2f or 4.5E2F
double It is a 64-bit floating point value We can use this if the value is bigger than float and it can be represented as  08.5 or 08.5e2 or 08.5E2
chararray It is a Character array (string) in Unicode UTF-8 format value JavaChain.com
bytearray The default datatype in pig is Byte array
boolean boolean represents true or false values. It could be either true/false and it is case sensitive.
datetime It displays the datetime 2016-01-14T00:00:00.000+00:00
biginteger It displays the Biginteger 70409060802
bigdecimal It displays the bigdecimal 198.78946646131311211

2.Complex Data Types

tuple it is the collections of one or more fields (Connecticut,Newjersey, Newyork)
bag it is the collection of one or more tuples {(Jack, Jill, JavaChain.com), (Connecticut, Newjersey, Newyork)}
map It has Key and value pair data [websitename#javachain.com]

Example Program:

EmployeeDetails.txt has the sample data.

Let us Load this data into Pig Relation using Pig Data Types.

Let us DESCRIBE the relation to see the Data type names.