I have two values in a PIG Latin script, what should I do to use them mathematically, like if I had two variables
A=(5)
B=(4)
How can I do A+B or something like that ?
I have two values in a PIG Latin script, what should I do to use them mathematically, like if I had two variables
A=(5)
B=(4)
How can I do A+B or something like that ?
You need to use Foreach stmt to do any mathematical operation, please see the below sample example.
input.txt
2,1
5,3
7,5
Pigscript:
A = LOAD 'input.txt' USING PigStorage(',') AS (val1:int , val1:int);
B = FOREACH A GENERATE (val1+val2) AS sum, (val1-val2) AS diff;
DUMP B;
Output:
(3,1)
(8,2)
(12,2)
Yes you can able to do any arithmetic operation in it but the thing is that any variable declaration is kind of different in pig latin -
what you have to do is -
and in any of the foreach statement you can use
this would work.