我编写了一个MapReduce代码,其中键和值都是整数.我正在使用单个Reducer.输出是这样的:
Key Value
1 78
128 12
174 26
2 44
2957 123
975 91
Run Code Online (Sandbox Code Playgroud)
是否有一种方法可以按键按升序对输出进行排序?这样输出看起来像这样:
1 78
2 44
128 12
174 26
975 91
2957 123
Run Code Online (Sandbox Code Playgroud)
我需要使用conf.setComparator吗?如果是的话,我该怎么做?
我正在写一个MapReduce工作,用于在Facebook上寻找普通朋友.
这是我的mapper的输入:
100, 200 300 400 500 600
200, 100 300 400
300, 100 200 400 500
400, 100 200 300
500, 100 300
600, 100
Run Code Online (Sandbox Code Playgroud)
这是我的映射器代码的一部分:
map{
String line = value.toString();
String[] LineSplits = line.split(",");
String[] friends = LineSplits[1].trim().split(" ");
for(int i =0; i<friends.length;i++) {
int friend2 = Integer.parseInt(friends[i]);
System.out.println(friend2);
}
int friend1 = Integer.parseInt(LineSplits[0]);
System.out.println(friend1);
}
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,我将获得正确的值friend2.(Intege.parseInt这里工作正常).变量friend1应该将值设为"100".但是Integer.ParseInt没有用,我收到这样的错误:
java.lang.Exception: java.lang.NumberFormatException: For input string: "100"
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:354)
Caused by: java.lang.NumberFormatException: For input string: "100" …Run Code Online (Sandbox Code Playgroud)