[英]The method setPartitionerClass(Class<?extendsPartitioner>) in the type Job is not applicable for the arguments (Class<WordCountPartitioner>)
My Driver code:我的驱动程序代码:
import org.apache.hadoop.conf.Configured;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCountDriver extends Configured {
public static void main(String[] args) throws Exception {
Job job = new Job();
job.setJarByClass(WordCountDriver.class);
job.setJobName("wordcountdriver");
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setMapperClass(WordCountMapper.class);
job.setReducerClass(WordCountReducer.class);
job.setPartitionerClass(WordCountPartitioner.class);
job.setNumReduceTasks(4);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
System.exit(job.waitForCompletion(true) ? 0 : -1);
}
}
My mapper code:我的映射器代码:
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.mapreduce.Mapper;
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
}
Reducer code:减速机代码:
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for(IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
}
}
Partitioner code:分区代码:
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Partitioner;
public class WordCountPartitioner implements Partitioner<Text, IntWritable> {
@Override
public void configure(JobConf arg0) {
// TODO Auto-generated method stub
}
@Override
public int getPartition(Text key, IntWritable value, int setNumRedTasks) {
String line = value.toString();
if (line.length() == 1) {
return 0;
}
if (line.length() == 2) {
return 1;
}
if (line.length() == 3) {
return 2;
} else {
return 3;
}
}
}
Why am I getting this error?为什么我收到这个错误?
You are mixing old ( org.apache.hadoop.mapred
) and new ( org.apache.hadoop.mapreduce
) API.您正在混合旧(
org.apache.hadoop.mapred
)和新( org.apache.hadoop.mapreduce
)API。 Your WordCountPartitioner
should extend org.apache.hadoop.mapreduce.Partitioner
class.你的
WordCountPartitioner
应该扩展org.apache.hadoop.mapreduce.Partitioner
类。
您的 WordCountPartitioner 需要扩展Partitioner
-Class 以作为该特定函数的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.