//实现reduce函数
public void reduce(IntWritable key,Iterable<IntWritable> values,Context context)
throws IOException,InterruptedException{
for(IntWritable val:values){
context.write(linenum, key);
linenum = new IntWritable(linenum.get()+1);
}
}
看楼主写的意思是,就是进reduce的时候就数据已经按key 排好顺序了是么?? 8楼说得很有道理,楼主的例子太过单调 按照例子我的结果有点不对
15 1
16 2
17 3
18 4
19 5
20 6
21 7
22 8
23 9
24 10
25 11
26 12
27 13
28 14 第47行转换数据类型有问题 data.set(Integer.parseInt(line));
一直报错,也不知道怎么改
java.lang.Exception: java.lang.NumberFormatException: For input string: ""
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at com.test.sort$Map.map(sort.java:45)
at com.test.sort$Map.map(sort.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at
org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
补充内容 (2016-9-13 10:24):
已经解决,因为出现了"".equal(line)的错误,也就是测试数据每两行数据之间不能有空行,删掉空行就运行正确了。 谢谢楼主分享 运行程序后sort_out总是为空,恳请赐教!
1 秒前
页:
1
[2]