在猪中存放时间

时间:2014-06-30 06:44:53

标签: hadoop apache-pig

我有这样的数据

Start_time End_time 12:10:30 13:10:00

我想将它存储在猪身上并计算经过的时间。 我怎么能在猪身上做到这一点? 我只是写了Start_time-End_time但结果是空白

1 个答案:

答案 0 :(得分:2)

查询将类似于:

time = LOAD '/user/name/input_folder/file_name' USING PigStorage() AS (sd:chararray, ed:chararray, t1:chararray, t2:chararray);
A = FOREACH time GENERATE $0, $1, GetHour(ToDate(t1,'HH:mm:ss')) as hour1, GetHour(ToDate(t2,'HH:mm:ss')) as hour2;
B = FOREACH A GENERATE ($3 - $2) as time_elapsed;
dump B;