How to get the current time stamp in PIG

孤人 提交于 2019-12-11 12:47:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!