Pig Latin – Eval Functions:
AVG, CONCAT:
C = FOREACH B GENERATE A.name, AVG(A.gpa);
X = FOREACH A GENERATE CONCAT(f2,f3);
COUNT:
X = FOREACH B GENERATE COUNT(A);
Other Eval functions are
DIFF – Compares two fields in a tuple.
IsEmpty – Checks if a bag or map is empty.
Max – To get the highest value.
Min – To get the lowest value.
TOKENIZE:
Splits a string and outputs a bag of words.
A = LOAD 'data' AS (f1:chararray);
DUMP A;
(Here is the first string.)
(Here is the second string.)
(Here is the third string.)
X = FOREACH A GENERATE TOKENIZE(f1);
DUMP X;
({(Here),(is),(the),(first),(string.)})
({(Here),(is),(the),(second),(string.)})
({(Here),(is),(the),(third),(string.)})