如何在 PIG 中获取当前时间戳 [英] How to get the current time stamp in PIG

查看:37
本文介绍了如何在 PIG 中获取当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于我正在编写的 PIG 脚本的查询.

I have a query with respect to a PIG script that I am writing.

如何在 PIG 脚本中获取当前的 Unix 时间戳?为此我需要任何 UDF 吗..或者 PIG 可以为我提供当前的时间戳吗?

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 ?

请多多指教.谢谢

推荐答案

我指出两个解决方案

第一个:

使用 CurrentTime(),将其转换为 ToUnixTime() 以获取时间戳.

use CurrentTime(),convert it to ToUnixTime() for need to get timestamp.

Ex:
 X = load "xx"  .........  ;

 X1 = FOREACH X GENERATE ToUnixTime(CurrentTime())

第二个:

从命令行作为参数传递.

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' ;

这篇关于如何在 PIG 中获取当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆