gpt4 book ai didi

hadoop - 为辅助排序创建复合键类

转载 作者:行者123 更新时间:2023-12-02 21:40:36 25 4
gpt4 key购买 nike

我正在尝试为Secondary Sort创建String uniqueCarrierint month的复合键类。谁能告诉我,相同的步骤是什么?

最佳答案

由于您未在compareTo方法中使用uniqueCarrier,因此您似乎遇到了平等问题。您需要在compareTo和equals方法中使用uniqueCarrier(还定义一个equals方法)。从java lang reference

The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.



您还可以实现 RawComparator,以便可以比较它们而无需反序列化以获得更快的性能。

但是,我建议(一如既往)不要写类似Secondary Sort这样的东西。这些已在Pig和Hive等项目中实现(以及其他数十种优化)。例如。如果您使用的是Hive,则只需编写以下内容:
SELECT ...
FROM my_table
ORDER BY month, carrier;

与尝试弄清楚如何编写次要排序(以及最终在需要再次使用它时,如何以通用方式进行编写)相比,上面的编写要简单得多。应该将MapReduce视为低级编程范例,并且仅在需要高性能(例如Pig或Hive)无法获得的高性能优化时,才应使用MapReduce。

编辑:忘记提及分组比较器,请参阅 Matt's answer

关于hadoop - 为辅助排序创建复合键类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29111713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com