Как решить, что chainmapper неприменим для ошибки аргументов при выполнении цепочки заданий в Mapreduce?

Я использую Hadoop 1.2.1, eclipse juno. Я пытаюсь связать три задачи карты в одном задании Mapreduce. при написании кода Mapreduce в eclipse я получаю сообщение об ошибке, например, chainmapper неприменим для аргументов, а также я не могу установить inputpath. Ниже приведен мой код mapreduce,

 package org.myorg;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.util.StringTokenizer;

import javax.security.auth.login.Configuration;

import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.MapRunnable;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapred.lib.ChainMapper;
import org.apache.hadoop.mapred.lib.ChainReducer;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.net.StaticMapping;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;


public class Recommand extends Configured implements Tool {



    public static class IdIndexMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text>{

        public void map(LongWritable key, Text val, OutputCollector<Text, Text> output,Reporter reporter)throws IOException{
            String[] ids;
            String ln=val.toString();
            ids=ln.split("\t");
            output.collect(new Text(ids[0]),new Text(ids[1]));

    }
}
    public static class FtrMapper extends MapReduceBase implements Mapper<Text, Text, Text, Text>{
        public void map(Text key, Text val, OutputCollector<Text, Text>output, Reporter reporter) throws IOException{
            String[] str;

            String lne=val.toString();
        while(lne.contains("M1024")){
                str=lne.split(",");
            String[] str1=new String[str.length];
                for(int i=0;i<str.length;i++){
                                if(str[i]=="M1024"){   //hre need to give id which we need to split;
                                    continue;
                                        }
                                str1[i]=str[i];
                                output.collect(key,new Text(str1[i]));                  
//                          System.out.println("str1 out:"+str[i]); 
                                    }
                            }


        }
    }

public static class CntMapper extends MapReduceBase implements Mapper<Text, Text, Text, IntWritable>{

    private final static IntWritable one=new IntWritable(1);
    private  Text word=new Text();
    public void map(Text key, Text val, OutputCollector<Text, IntWritable>output, Reporter reporter)throws IOException{
        String line = val.toString();
    StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            output.collect(word, one);
                    }
                }
            }


public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable>{
    public void reduce(Text key, Iterable<IntWritable>values, OutputCollector<Text, IntWritable>output, Reporter reporter)throws IOException{
        int sum=0;
        for(IntWritable val:values){
            sum+=val.get();
                    }
        output.collect(key,new IntWritable(sum));
                    }
                }   

static int printUsage() {
    System.out.println("recommand  ");
    ToolRunner.printGenericCommandUsage(System.out);
    return -1;
}

public int run(String[] args) throws Exception {
    JobConf conf = new JobConf(getConf(), Recommand.class);
    conf.setJobName("wordcount");

    if (args.length != 2) {
        System.out.println("ERROR: Wrong number of parameters: " +
                args.length + " instead of 2.");
        return printUsage();
    }
    FileInputFormat.setInputPaths(conf, args[0]);
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    JobConf mapAConf = new JobConf(false);
    ChainMapper.addMapper(conf, IdIndexMapper.class, LongWritable.class, Text.class, Text.class, Text.class, true, mapAConf);

    JobConf mapBConf = new JobConf(false);
    ChainMapper.addMapper(conf, FtrMapper.class, Text.class, Text.class, Text.class, Text.class, true, mapBConf);

    JobConf mapCConf = new JobConf(false);
    ChainMapper.addMapper(conf, CntMapper.class, Text.class, Text.class, Text.class, IntWritable.class, true, mapBConf);

    JobConf reduceConf = new JobConf(false);
    ChainReducer.setReducer(conf, Reduce.class, Text.class, IntWritable.class, Text.class, IntWritable.class, true, reduceConf);

    JobClient.runJob(conf);
    return 0;
}

public static void main(String[] args) throws Exception {
    int res = ToolRunner.run(new org.apache.hadoop.conf.Configuration(), Recommand(), args);
    System.exit(res);
}
}

Может ли кто-нибудь помочь мне решить эту проблему, пожалуйста?


person Karthick    schedule 11.08.2014    source источник
comment
Вы можете опубликовать сообщение об ошибке, пожалуйста?   -  person vefthym    schedule 11.08.2014
comment
первый пришел на addmapper, который является методом addMapper(JobConf, Class‹? extends Mapper‹K1,V1,K2,V2››, Class‹? extends K1›, Class‹? extends V1›, Class‹? extends K2›, Class‹? extends V2›, boolean, JobConf) в типе ChainMapper неприменим для аргументов (JobConf, Class‹Recommand.IdIndexMapper›, Class‹LongWritable›, Class‹Text›, Class‹Text›, Class‹Text› , boolean, JobConf) 2 один из установки Inputpath, который является Метод setInputPaths(Job, String) в типе FileInputFormat неприменим для аргументов (JobConf, String)   -  person Karthick    schedule 11.08.2014
comment
Попробуйте ответить на этот пост (возможный дубликат): stackoverflow.com/questions/6840922/   -  person vefthym    schedule 11.08.2014
comment
да, я пробовал то же самое, что и вы. Когда я пробую этот код в eclipse, он показывает ошибку, о которой я сказал, в строке ChainMapper.addMapper. Я не знаю, как их решить.   -  person Karthick    schedule 11.08.2014
comment
Я так не думаю... Ответ на упомянутый пост импортирует org.apache.hadoop.mapred.Mapper;, а не org.apache.hadoop.mapreduce.Mapper;, как вы. Вы пробовали это?   -  person vefthym    schedule 11.08.2014
comment
vefthym, спасибо, я тоже столкнулся с той же проблемой, и imports org.apache.hadoop.mapred.Mapper; работает на меня   -  person user3302083    schedule 01.04.2016


Ответы (1)


Убедитесь в следующем, чтобы избежать этой ошибки

  1. Оба класса расширяют класс Mapper.
  2. Используемый класс ChainMapper относится к правильному API, в зависимости от того, что применимо к вашему коду.

org.apache.hadoop.mapreduce.lib.chain.ChainMapper или импортировать org.apache.hadoop.mapred.lib.ChainMapper

person Karthik Talakanti    schedule 25.02.2018