如何在 Apache PIG 上将时间和日期转换为 Unix 时间戳?

How to convert time and date to Unix timestamp on Apache PIG?

我有一个包含(日期、时间、ip、id)的元组

(23/04/2014, 19:14:30,192.168.5.28, al00000)

我需要将日期和时间转换为 Unix 时间戳

(1398280470, 192.168.5.28, al00000)

我该怎么做?

参考: http://pig.apache.org/docs/r0.11.1/func.html#datetime-functions

输入:

23/04/2014,19:14:30,192.168.5.28,al00000

猪脚本:

A = LOAD 'input_data.csv' USING PigStorage(',')  AS (date:chararray,time:chararray,ip:chararray,id:chararray);
B = FOREACH A GENERATE ToUnixTime(ToDate(CONCAT(date, time),'dd/MM/yyyyHH:mm:ss', 'GMT')) AS unix_time, ip, id;

输出:

(1398280470,192.168.5.28,al00000)