我正在阅读和实施这个教程。最后实现了mapper、reducer和driver三个类。我复制了网页上给出的三个类的代码。但接下来的两个错误没有发生away:-
Map器类********************************************
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class WordCountMapper extends MapReduceBase //////Here WordCountMapper was underlined as error source by Eclipse
implements Mapper<LongWritable, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(WritableComparable key, Writable value,
OutputCollector output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer itr = new StringTokenizer(line.toLowerCase());
while(itr.hasMoreTokens()) {
word.set(itr.nextToken());
output.collect(word, one);
}
}
}
错误是:
The type WordCountMapper must implement the inherited abstract method
Mapper<LongWritable,Text,Text,IntWritable>.map(LongWritable, Text,
OutputCollector<Text,IntWritable>, Reporter)
驱动程序类(wordcount.java)************
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
public class WordCount {
public static void main(String[] args) {
JobClient client = new JobClient();
JobConf conf = new JobConf(WordCount.class);
// specify output types
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
// specify input and output dirs
FileInputPath.addInputPath(conf, new Path("input")); //////////FileInputPath was underlined
FileOutputPath.addOutputPath(conf, new Path("output")); ////////FileOutputPath as underlined
// specify a mapper
conf.setMapperClass(WordCountMapper.class);
// specify a reducer
conf.setReducerClass(WordCountReducer.class);
conf.setCombinerClass(WordCountReducer.class);
client.setConf(conf);
try {
JobClient.runJob(conf);
} catch (Exception e) {
e.printStackTrace();
}
}
}
错误是:
1. FileInputPath cannot be resolved
2. FileOutputPath cannot be resolved
有人能告诉我问题出在哪里吗?提前谢谢。
2条答案
按热度按时间iyr7buue1#
使用
org.apache.hadoop.mapred.FileInputFormat
,org.apache.hadoop.mapred.FileOutputFormat
并按如下方式修改代码:bt1cpqcv2#
正如sachinjose所说,当我将代码更改为:-
在本例中,第一个错误也得到了解决(我正在复制user2357112的答案):-
您尚未提供任何类型参数。mapper是一个通用接口;它通过输入和输出键和值类型的类型参数进行参数化。用您需要的类型在以下代码中填写k1、v1、k2和v2: