我正在研究一个hadoop项目,经过多次访问各种博客和阅读文档,我意识到我需要使用hadoop框架提供的二次排序功能.
我的输入格式是以下形式:
DESC(String) Price(Integer) and some other Text
我希望reducer中的值是Price的降序.同时在比较DESC时,我有一个方法,它取两个字符串和百分比,如果两个字符串之间的相似性等于或大于百分比,那么我应该认为它们是相等的.
问题是在Reduce Job完成之后我可以看到一些DESC与其他字符串相似但它们在不同的组中.
这是我的Composite键的compareTo方法
public int compareTo(VendorKey o) {
int result =-
result = compare(token, o.token, ":") >= percentage ? 0:1;
if (result == 0) {
return pid> o.pid ?-1: pid < o.pid ?1:0;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
比较分组比较器的方法
public int compare(WritableComparable a, WritableComparable b) {
VendorKey one = (VendorKey) a;
VendorKey two = (VendorKey) b;
int result = ClusterUtil.compare(one.getToken(), two.getToken(), ":") >= one.getPercentage() ? 0 : 1;
// if (result != …
Run Code Online (Sandbox Code Playgroud)