Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hadoop获取日期之间的时差_Hadoop_Mapreduce_Hadoop Partitioning - Fatal编程技术网

Hadoop获取日期之间的时差

Hadoop获取日期之间的时差,hadoop,mapreduce,hadoop-partitioning,Hadoop,Mapreduce,Hadoop Partitioning,我在hadoop中遇到了类似这样的问题 由于我的映射器,我得到了以下结果 KeyValue1, 2014-02-01 20:42:00 KeyValue1, 2014-02-01 20:45:12 KeyValue1, 2014-05-01 10:35:02 KeyValue2, 2014-03-01 01:45:12 KeyValue2, 2014-03-01 02:08:18 KeyValue3, 2014-02-01 20:45:12 KeyValue4, 2015-02-01 05:45

我在hadoop中遇到了类似这样的问题

由于我的映射器,我得到了以下结果

KeyValue1, 2014-02-01 20:42:00
KeyValue1, 2014-02-01 20:45:12
KeyValue1, 2014-05-01 10:35:02
KeyValue2, 2014-03-01 01:45:12
KeyValue2, 2014-03-01 02:08:18
KeyValue3, 2014-02-01 20:45:12
KeyValue4, 2015-02-01 05:45:12
KeyValue4, 2013-02-01 10:45:12
然后继续

在一天结束的时候,我想要这个

 KeyValue1, TimeDifference(first occurrence - last occurrence)
 KeyValue2, TimeDifference(first occurrence - last occurrence)
 KeyValue3, -occured once-
 KeyValue4, TimeDifference(first occurrence - last occurrence)

非常感谢您的任何意见。干杯

有多种方法。我建议使用复合键。创建自定义分区器、KeyComparator和GroupComparator。然后在减速机侧,您可以简单地选择第一行和最后一行,并采取不同

向减速器发出相同的顺序。在reducer中,对于每个唯一键,迭代值列表。为第一个日期和最后一个日期设置两个变量,并在日期变大或变小时进行更新。在迭代结束时,获取差异并发射。