Mohan.V Mohan.V - 3 months ago 34
Bash Question

How to get EPOCH time in PIG?

I am completely new to pig.
Started to learn on my own and trying to know PIG.
Can anyone please suggest me to get the current system epoch time using pig by reading a words.txt file which having words.

I need the output as

word1_1234567890 word2_1234567890 word3_1234567890


And how can we call the shell script in PIG script

Because I have already written the Shell script.

Any Help.

Thanks in Advance.

Mohan.v

Answer

Use CONCAT to combine your word with the epochtime.You can get the epochtime using ToUnixTime()

A = LOAD 'words.txt' AS (word:chararray);
B = FOREACH A GENERATE CONCAT(CONCAT(A.word,'_'),(chararray)ToUnixTime(CurrentTime());
DUMP B;

Let's say your shell script is names test.sh

%declare my_shell_script 'test.sh'
A = LOAD 'data.txt' AS (f1:int,f2:chararray);
B = FOREACH A GENERATE '$my_shell_script';

If your shell script has parameter say param1

%declare my_shell_script 'test.sh $param1'
A = LOAD 'data.txt' AS (f1:int,f2:chararray);
B = FOREACH A GENERATE '$my_shell_script';