有没有办法在猪中添加日期时间?

Pat*_*len 0 hadoop apache-pig

what I would like to do in pig is something that is very common in sql. I have date field that is of the form yyy-mm-dd hh:mm:ss and I have another field that contains an integer which represents an amount of hours. Is there a way to easily add the integer to the datetime field so that we get a result of what we expect with clock math.

Example: date is 2013-06-01 : 23:12:12.

Then I add 2 hours

I should get 2013-06-02 01:12:12.

Tar*_*riq 6

最新发布的Pig(0.11.0)应该是可能的.但是小时(时间)应该是按照ISO8601 Duration Format.它提供了一个类AddDuration,允许我们使用Duration对象添加DateTime对象.您可以在此页面找到有关AddDuration的更多信息.

编辑:

是的,您可以添加负数小时.我在我的Ubuntu盒子上尝试过这个:

输入:

2009-01-07T01:07:01.000Z,PT1S
2008-02-06T02:06:02.000Z,PT1M
2007-03-05T03:05:03.000Z,PT-1H
Run Code Online (Sandbox Code Playgroud)

查询:

grunt> a = LOAD '/pig.txt' USING PigStorage(',') AS (dt:datetime, dr:chararray);
grunt> b = FOREACH a GENERATE AddDuration(dt, dr) AS dt1;
grunt> dump b; 
Run Code Online (Sandbox Code Playgroud)

输出:

(2009-01-07T01:07:02.000Z)
(2008-02-06T02:07:02.000Z)
(2007-03-05T02:05:03.000Z)
Run Code Online (Sandbox Code Playgroud)