简体   繁体   English

方法 setPartitionerClass(Class<?extendsPartitioner> ) 类型 Job 不适用于参数 (Class<WordCountPartitioner> )

[英]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.

相关问题 类型中的方法不适用于参数(类 <Main> )? - The method in the type is not applicable for the arguments (Class<Main>)? 方法 insert(String, Class<t> ) 类型中的数据不适用于 arguments</t> - The method insert(String, Class<T>) in the type Data is not applicable for the arguments 类Class中的方法foo(T [])不适用于自变量(向量 <Integer> ) - The method foo(T[]) in the type Class is not applicable for the arguments (Vector<Integer>) 方法播放(类 <T> )不适用于参数(类) - The method play(Class<T>) is not applicable for the arguments (Class) Axis2 Web服务:类类型中的方法getConstructor(Class [])不适用于自变量(类 <T> ) - Axis2 Web Service : The method getConstructor(Class[]) in the type Class is not applicable for the arguments (Class<T>) Morphia错误:fromDBObject(Class <T> ,类型为Morphia的BasicDBObject不适用于参数(类 <Suite> ,DBObject) - Morphia Error : The method fromDBObject(Class<T>, BasicDBObject) in the type Morphia is not applicable for the arguments (Class<Suite>, DBObject) Java泛型编译错误-方法method(Class <capture#1-of ? extends Interface> ) <type> 不适用于参数 - Java generics compilation error - The method method(Class<capture#1-of ? extends Interface>) in the type <type> is not applicable for the arguments 类型中的方法不适用于参数 - Method in the type is not applicable to the arguments 类型中的方法不适用于参数 - The method in the type is not applicable for the arguments 类型中的方法不适用于参数 - the method in type not applicable for the arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM