PIG LATIN OVERVIEW
AND DATA TYPES
-CD012,CD028,CD041,CD47
PIG LATIN OVERVIEW
Pig Latin Statements:
• Pig Latin statements are basic constructs to process data using Pig.
• Pig Latin statement is an operator.
• An operator in Pig Latin takes a relation as input and yields another
relation as output.
• Pig Latin statements include schemas and expressions to process
data.
• Pig Latin statements should end with a semi-colon.
Pig Latin Statements are generally ordered as follows:
• LOAD statement that reads data from the file system.
• Series of statements to perform transformations.
• DUMP or STORE to display/store result.
The following is a simple Pig Latin script to load, filter, and store "student"
data.
A = load 'student' (rollno, name, gpa);
A = filter A by gpa > 4.0;
A = foreach A generate UPPER (name);
STORE A INTO 'myreport'
Note: In the above example A is a relation and NOT a variable.
Pig Latin: Keywords
• Keywords are reserved. It cannot be used to name things
Pig Latin: Identifiers
• Identifiers are names assigned to fields or other data structures.
• It should begin with a letter and should be followed only by letters,
numbers, and underscores.
Pig Latin: Comments
In Pig Latin two types of comments are supported:
• Single-line comments that begin with "--".
• Multiline comments that begin with "/* and end with */".
Pig Latin: Case Sensitivity
• Keywords are not case sensitive such as LOAD, STORE, GROUP, FOREACH,
DUMP, etc.
• Relations and paths are case-sensitive.
• Function names are case sensitive such as PigStorage, COUNT
Operators in Pig Latin:
• Arithmetic Operators:
• +: Addition − It simply adds values on either side of the operator.
For Example: 60, comes to adding A+B.(If A=20, B=40)
• −: Subtraction – This operator subtracts the right-hand operand from the left-hand
operand.
For Example: −20, comes on subtracting A-B
• *: Multiplication − It simply Multiplies values on either side of the operators.
For Example: 800, it comes to multiplying A*B.
• /: Division − This operator divides the left-hand operand by the right-hand
operand
For Example: 2, it comes to dividing, b/a
• %: Modulus − It Divides the left-hand operand by the right-hand operand and
returns the remainder
For Example: 0, comes to dividing, b % a.
• Comparison Operators:
• == : Equal − This operator checks if the values of two operands are equal or not. So,
if yes, then the condition becomes true.
For Example- (a = b) is not true
• !=:Not Equal − It will check if the values of two operands are equal or not. So, if the
values are not equal, then condition becomes true.
For Example- (a != b) is true.
• >:Greater than − This operator checks if the value of the left operand is greater than
the value of the right operand. Hence, if yes, then the condition becomes true.
For Example- (a > b) is not true.
• <:Less than − It simply checks if the value of the left operand is less than the value
of the right operand. So, if yes, then the condition becomes true.
For Example- (a < b) is true.
• >= : Greater than or equal to − It will check if the value of the left operand is greater
than or equal to the value of the right operand. Hence, if yes, then the condition
becomes true.
For Example- (a >= b) is not true.
• <=: Less than or equal to − This operator checks if the value of the left operand is
less than or equal to the value of the right operand. So, if yes, then the condition
becomes true. For Example- (a <= b) is true.
• NULL VALUES:
• is null: Returns true if the tested value is null, and false otherwise.
• is not null: Returns true if the tested value is not null, and false otherwise.
• BOOLEAN OPERATORS:
• AND:This operator evaluates to true only if both operands are true, otherwise, it
evaluates to false.
• OR:This operator evaluates to true if at least one of the operands is true; it
evaluates to false only if both operands are false.
• NOT:This operator negates the value of its operand. If the operand is true, not
makes it false, and vice versa.
DATA TYPES
• Simple Data Types
• In Pig, fields of unspecified types are considered as an array of bytes which
is known as byte array.
• Null: In Pig Latin, NULL denotes a value that is unknown or is
non-existent.
• Complex Data type:
Complex data types consist of a bit of logical and complicated data
type. The following are the complex data type:
THANK YOU