Điều này có vẻ giống như một câu hỏi ngu ngốc, nhưng tôi không thấy vấn đề trong các loại của tôi trong mã MapReduce của tôi cho hadoopsai lớp chính: Văn bản được phát không IntWritable
Như đã nêu trong câu hỏi vấn đề là nó là mong đợi IntWritable nhưng tôi đi qua nó một đối tượng Text trong collector.collect của bộ giảm tốc.
cấu hình Công việc của tôi có các lớp sau mapper đầu ra:
conf.setMapOutputKeyClass(IntWritable.class);
conf.setMapOutputValueClass(IntWritable.class);
Và các lớp đầu ra giảm sau:
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
lớp bản đồ của tôi có định nghĩa sau đây:
public static class Reduce extends MapReduceBase implements Reducer<IntWritable, IntWritable, Text, IntWritable>
với chức năng được yêu cầu:
public void reduce(IntWritable key, Iterator<IntWritable> values, OutputCollector<Text,IntWritable> output, Reporter reporter)
Và sau đó nó không thành công khi tôi gọi:
output.collect(new Text(),new IntWritable());
Tôi khá mới để lập bản đồ giảm nhưng tất cả các loại dường như phù hợp, nó biên dịch nhưng sau đó thất bại trên dòng đó nói nó chờ đợi một IntWritable là chìa khóa cho lớp giảm. Nếu những vấn đề tôi đang sử dụng 0,21 phiên bản của Hadoop
Đây là lớp bản đồ của tôi:
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, IntWritable, IntWritable> {
private IntWritable node = new IntWritable();
private IntWritable edge = new IntWritable();
public void map(LongWritable key, Text value, OutputCollector<IntWritable, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
node.set(Integer.parseInt(tokenizer.nextToken()));
edge.set(Integer.parseInt(tokenizer.nextToken()));
if(node.get() < edge.get())
output.collect(node, edge);
}
}
}
và lớp giảm của tôi:
public static class Reduce extends MapReduceBase implements Reducer<IntWritable, IntWritable, Text, IntWritable> {
IntWritable $ = new IntWritable(Integer.MAX_VALUE);
Text keyText = new Text();
public void reduce(IntWritable key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
ArrayList<IntWritable> valueList = new ArrayList<IntWritable>();
//outputs original edge pair as key and $ for value
while (values.hasNext()) {
IntWritable value = values.next();
valueList.add(value);
keyText.set(key.get() + ", " + value.get());
output.collect(keyText, $);
}
//outputs all the 2 length pairs
for(int i = 0; i < valueList.size(); i++)
for(int j = i+1; i < valueList.size(); j++)
output.collect(new Text(valueList.get(i).get() + ", " + valueList.get(j).get()), key);
}
}
và cấu hình công việc của tôi:
JobConf conf = new JobConf(Triangles.class);
conf.setJobName("mapred1");
conf.setMapOutputKeyClass(IntWritable.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path("mapred1"));
JobClient.runJob(conf);
Nó có vẻ tốt. Bạn có thể đăng các lớp thư, bản đồ và giảm bớt –
Chỉ cần cập nhật câu hỏi với các lớp bản đồ và giảm bớt, mặc dù tôi mới sử dụng hadoop và không biết lớp thư là gì? Tôi đã làm điều này bằng cách sửa đổi ví dụ WordCount mà tôi không nghĩ là bao gồm cả lớp đó. – user1084563