本文介绍了在 PIG 中查找 start_times 和 end_times 之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在 PIG 中找到两次之间的差异...

Could anyone please tell me how to find the difference between two times in PIG...

例如,下面是示例 Start_Times 和 End_Times,我需要在 PIG 中找到 Start_Time 和 End_Time 之间的差异.

For e.g., Below are the sample Start_Times and End_Times, I need to find the difference between Start_Time and End_Time in PIG.

12:31:38,14:54:04
10:18:34,13:30:56
13:37:43,15:18:57
08:15:10,11:28:17

提前致谢...

推荐答案

找不到直接的方法.这是一个解决方法:

Couldn't find a straightforward way. Here is a workaround:

    t = LOAD ' input/data' USING PigStorage(',') as (time1:chararray,time2:chararray);
    u = FOREACH t GENERATE SecondsBetween(ToDate(time2,'HH:mm:ss'),ToDate(time1,'HH:mm:ss')) as seconds;
    v = FOREACH u GENERATE seconds/3600 as hours,(seconds%3600)/60 as minutes,(seconds%3600)%60 as seconds;
    STORE v into 'output/data' USING PigStorage(':');

使用此代码输出示例数据:

Output for your sample data with this code:

    2:22:26
    3:12:22
    1:41:14
    3:13:7

这篇关于在 PIG 中查找 start_times 和 end_times 之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 08:23