Java Hadoop与Eclipse的集成
我正在阅读和实施教程。最后,我实现了三个类:映射器、减速器和驱动程序。我复制了网页上给出的所有三个类的确切代码。但以下两个错误并没有消失:- *****************映射器类*************************************************************Java Hadoop与Eclipse的集成,java,eclipse,hadoop,Java,Eclipse,Hadoop,我正在阅读和实施教程。最后,我实现了三个类:映射器、减速器和驱动程序。我复制了网页上给出的所有三个类的确切代码。但以下两个错误并没有消失:- *****************映射器类************************************************************* import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.io.IntWr
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);
}
}
}
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();
}
}
}
错误是:
The type WordCountMapper must implement the inherited abstract method
Mapper<LongWritable,Text,Text,IntWritable>.map(LongWritable, Text,
OutputCollector<Text,IntWritable>, Reporter)
1. FileInputPath cannot be resolved
2. FileOutputPath cannot be resolved
有人能告诉我问题出在哪里吗?提前感谢。使用
org.apache.hadoop.mapred.FileInputFormat
,org.apache.hadoop.mapred.FileOutputFormat
并按如下方式修改代码:
// specify input and output dirs
FileInputFormat.addInputPath(conf, new Path("input"));
FileOutputFormat.addOutputPath(conf, new Path("output"));
正如Sachinjose所说,当我将代码更改为:-
FileInputFormat.addInputPath(conf, new Path("input"));
FileOutputFormat.setOutputPath(conf, new Path("output"));
第一个错误在示例中也得到了解决(我正在复制user2357112的答案):-
您尚未提供任何类型参数。映射器是一个通用接口;它通过输入和输出键和值类型的类型参数进行参数化。用您需要的类型在以下代码中填写K1、V1、K2和V2:
public class WordMapper extends MapReduceBase implements Mapper<K1, V1, K2, V2> {
public void map(K1 key,
V1 value,
OutputCollector<K2, V2> output,
Reporter reporter)
throws IOException {
whatever();
}
}
公共类WordMapper扩展MapReduceBase实现Mapper{
公共空隙图(K1键,
V1值,
输出采集器输出,
(记者)
抛出IOException{
随便什么;
}
}