import java.io.IOException;
import java.util.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class CommonFriends {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private IntWritable friend = new IntWritable();
private Text friends = new Text();
public void map(Object key, Text value, Context context ) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString(),"\n");
while (itr.hasMoreTokens()) {
String[] line = itr.nextToken().split(" ");
if(line.length > 2 ){
int person = Integer.parseInt(line[0]);
for(int i=1; i<line.length;i++){
int ifriend = Integer.parseInt(line[i]);
friends.set((person < ifriend ? person+"-"+ifriend : ifriend+"-"+person));
for(int j=1; j< line.length; j++ ){
if( i != j ){
friend.set(Integer.parseInt(line[j]));
context.write(friends, friend);
}
}
}
}
}
}
}
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,Text> {
private Text result = new Text();
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
HashSet<IntWritable> duplicates = new HashSet();
ArrayList<Integer> tmp = new ArrayList();
for (IntWritable val : values) {
if(duplicates.contains(val))
tmp.add(val.get());
else
duplicates.add(val);
}
result.set(tmp.toString());
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Common Friends");
job.setJarByClass(CommonFriends.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
错误:java。io。IOException:错误的值类:class org。阿帕奇。hadoop。io。文本不是类别组织。阿帕奇。hadoop。io。可写入的
位于组织。阿帕奇。hadoop。映射。IFile$编写器。追加(IFile.java:194)
位于组织。阿帕奇。hadoop。映射。任务$CombineOutputCollector。收集(Task.java:1350)
位于组织。阿帕奇。hadoop。映射。任务$NewCombinerRunner$OutputConverter。写入(Task.java:1667)
位于组织。阿帕奇。hadoop。mapreduce。任务TaskInputOutputContextImpl。写入(TaskInputOutputContextImpl.java:89)
位于组织。阿帕奇。hadoop。mapreduce。lib。减少WrappedReducer$上下文。write(WrappedReducer.java:105)
在CommonFriends$IntSumReducer。reduce(CommonFriends.java:51)
在CommonFriends$IntSumReducer。reduce(CommonFriends.java:38)
位于组织。阿帕奇。hadoop。mapreduce。减速器。运行(Reducer.java:171)
位于组织。阿帕奇。hadoop。映射。任务$NewCombinerRunner。联合收割机(Task.java:1688)
位于组织。阿帕奇。hadoop。映射。MapTask$MapOutputBuffer。sortAndSpill(MapTask.java:1637)
位于组织。阿帕奇。hadoop。映射。MapTask$MapOutputBuffer。刷新(MapTask.java:1489)
位于组织。阿帕奇。hadoop。映射。MapTask$NewOutputCollector。关闭(MapTask.java:723)
位于组织。阿帕奇。hadoop。映射。MapTask。runNewMapper(MapTask.java:793)
位于组织。阿帕奇。hadoop。映射。MapTask。运行(MapTask.java:341)
位于组织。阿帕奇。hadoop。映射。YarnChild 2美元。run(YarnChild.java:164)
在java。安全AccessController。doPrivileged(本机方法)
在javax。安全授权。主题doAs(主题:java:422)
位于组织。阿帕奇。hadoop。安全用户组信息。doAs(UserGroupInformation.java:1657)
位于组织。阿帕奇。hadoop。映射。YarnChild。main(YarnChild.java:158)
这是我的代码,错误消息如下。
有什么想法吗??
我认为mapper和reducer的输出类的配置问题
输入文件是文件中的数字列表。
如果需要,将提供更多详细信息。
程序在朋友之间查找常见的朋友