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

时间:2015-10-02 21:15:28

标签: apache-pig

我有一个元组(date,time,ip,id)

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

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

(1398280470, 192.168.5.28, al00000)

我该怎么做?

1 个答案:

答案 0 :(得分:0)

参考: 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)