问题
I have a query with respect to a PIG script that I am writing.
How can I get the current Unix Time Stamp in PIG script.? Do I need any UDF for the purpose.. or can PIG provide me the currnet time stamp ?
Kindly advice me. Thanks
回答1:
I am pointing two solutions
first one:
use CurrentTime(),convert it to ToUnixTime() for need to get timestamp.
Ex:
X = load "xx" ......... ;
X1 = FOREACH X GENERATE ToUnixTime(CurrentTime())
second one:
Passing from command line as a parameter.
pig -f myscript.pig --param timestamp=$(date +%s)
----in myscript.pig ----
%declare time '$timestamp ';
X1 = FOREACH X GENERATE '$time' ;
回答2:
You do need to use a UDF. Good news is that it ships with Pig. It's called CurrentTime
. Take a look at the docs page here for all the built-in functions.
来源:https://stackoverflow.com/questions/29206808/how-to-get-the-current-time-stamp-in-pig