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
Java 如何在mapreduce中使用组比较器?_Java_Hadoop_Testing_Mapreduce - Fatal编程技术网

Java 如何在mapreduce中使用组比较器?

Java 如何在mapreduce中使用组比较器?,java,hadoop,testing,mapreduce,Java,Hadoop,Testing,Mapreduce,我读过这些文章 所以我有点理解它是如何工作的 问题是。。。测试时,没有这条线 driver.setKeyGroupingComparator(groupComparator); 我在减速器中得到以下输出 0000000000_44137 902996760100000_44137 9029967602_44137 90299676030000_44137 9029967604_44137 905000_38704 9050000001_38702 9050000001_38704 9050

我读过这些文章

所以我有点理解它是如何工作的

问题是。。。测试时,没有这条线

driver.setKeyGroupingComparator(groupComparator);
我在减速器中得到以下输出

0000000000_44137
902996760100000_44137
9029967602_44137
90299676030000_44137
9029967604_44137
905000_38704
9050000001_38702
9050000001_38704
9050000001_38705
9050000001_38706
9050000001_38714
9050000002_38704
9050000002_38706
9050000011_38704
9050000011_38706
9050000021_38702
9050000031_38704
9050000031_38705
9050000031_38714
有了它,我可以

0000000000_44137
902996760100000_44137
9029967602_44137
90299676030000_44137
9029967604_44137
905000_38704
9050000001_38702
9050000002_38704
9050000011_38704
9050000021_38702
9050000031_38704
减速器

@Override
public void reduce(CompositeKey key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
    System.out.println(key.getFirst() + "_" + key.getSecond());
}
但是

0000000000 44137 value1
9050000001 38702 value1 value2 value3 value4 value5
除了第一个,所有的对半都丢失了。如何迭代键的每个右部分?可能吗

我的群组比较器

public class GroupComparator extends WritableComparator {
    public GroupComparator() {
        super(CompositeKey.class, true);
    }
    @Override
    public int compare(WritableComparable a,
                       WritableComparable b) {
        CompositeKey lhs = (CompositeKey)a;
        CompositeKey rhs = (CompositeKey)b;
        return lhs.getFirst().compareTo(rhs.getFirst());
    }
}

您的输出看起来是正确的。如果要在分组后访问键的所有第二部分,则需要将其放入值中。您的输出看起来是正确的。如果要在分组后访问键的所有第二部分,则需要将其放入值中。
public class GroupComparator extends WritableComparator {
    public GroupComparator() {
        super(CompositeKey.class, true);
    }
    @Override
    public int compare(WritableComparable a,
                       WritableComparable b) {
        CompositeKey lhs = (CompositeKey)a;
        CompositeKey rhs = (CompositeKey)b;
        return lhs.getFirst().compareTo(rhs.getFirst());
    }
}