2016-04-09 17 views
0

私は、「エラー:java.io.IOException:マップからのキーの型の不一致:予想されるorg.apache.hadoop.io」というエラーメッセージが表示される.IntWritable、受け取ったorg.apache.hadoop.io.LongWritable "どこで私はプログラム内のどこでもLongWritableを使用していないことがわかります。この問題を解決し、どこが間違っていたかを修正してください。mapreduceプログラムを実行中に問題が発生しました

プログラム: パブリッククラスcustomeWordCount {

public static class Map extends Mapper<Text, IntWritable, Text,IntWritable>{ 
    private static IntWritable count; 
    private static Text wordCropped; 
    public void map(IntWritable key, Text value, 
      Context context) 
      throws IOException,InterruptedException { 
    TreeMap map = new TreeMap(String.CASE_INSENSITIVE_ORDER); 
     String line = value.toString(); 
     StringTokenizer tokenizer = new StringTokenizer(line); 


     String word = null; 
     while (tokenizer.hasMoreTokens()) { 
      word =tokenizer.nextToken(); 

     if(word.length()>=3){ 
      wordCropped.set(word.substring(0, 3)); 

      if(map.containsKey(wordCropped.toString().toLowerCase())){ 
       count = (IntWritable) map.get(wordCropped); 


       context.write(wordCropped, (IntWritable)count); 

      } 
      else { 
       context.write(wordCropped, (IntWritable)count); 
      } 
     } 
      } 


    } 

} 
public static class Reduce extends Reducer<Text,IntWritable,Text,IntWritable>{ 

    public void reduce(Text key, Iterable<IntWritable> values, 
      Context context) 
      throws IOException,InterruptedException { 
     int sum=0; 
     // TODO Auto-generated method stub 
     for(IntWritable x: values) 
     { 
      sum++; 

     } 
     context.write(key, new IntWritable(sum)); 

    } 

} 

public static void main(String[] args) throws Exception { 
    // TODO Auto-generated method stub 

    //JobConf conf = new JobConf(Al.class); 
    Configuration conf= new Configuration(); 


    //conf.setJobName("mywc"); 
    Job job = new Job(conf,"Custome_count"); 

    job.setJarByClass(customeWordCount.class); 
    job.setMapperClass(Map.class); 
    job.setReducerClass(Reduce.class); 

    //conf.setMapperClass(Map.class); 
    //conf.setReducerClass(Reduce.class); 
    job.setMapOutputKeyClass(IntWritable.class); 

    //Defining the output value class for the mapper 

    job.setMapOutputValueClass(Text.class); 

    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(IntWritable.class); 

    job.setInputFormatClass(TextInputFormat.class); 
    job.setOutputFormatClass(TextOutputFormat.class); 



    Path outputPath = new Path(args[1]); 

     //Configuring the input/output path from the filesystem into the job 

    FileInputFormat.addInputPath(job, new Path(args[0])); 
    FileOutputFormat.setOutputPath(job, new Path(args[1])); 

     //deleting the output path automatically from hdfs so that we don't have delete it explicitly 

    outputPath.getFileSystem(conf).delete(outputPath); 

     //exiting the job only if the flag value becomes false 

    System.exit(job.waitForCompletion(true) ? 0 : 1); 
} 

}

+0

public static class Map extends Mapper<LongWritable, Text, Text,IntWritable> 

し、マップのメソッドのシグネチャは、に変更する必要があります私はjob.setMapOutputValueClass(Text.class)を変更しようとしました。 to job.setMapOutputValueClass(IntWritable.class); job.setMapInputValueClass(IntWritable.class)の同様の変更。 to job.setMapInputValueClass(Text.class);しかし、私はエラーが表示されます "タイプの不一致のマップから:期待org.apache.hadoop.io.Text、受信org.apache.hadoop.io.LongWritable " ここで私を手伝ってくれる専門家。事前に感謝:) – user1708054

+0

この問題を解決するために誰かを依頼してください。 – user1708054

答えて

0

あなたが入力としてテキストファイルを持っているので、使用されるのInputFormatはTextInputFormatです。このフォーマットは、キーとしてLongWritableを、値としてテキストを持ちます。

あなたのマッパーとして宣言されなければならない、と述べた: ..メインクラスでいくつかの問題があるように私は感じ

public void map(LongWritable key, Text value, Context context) 
     throws IOException,InterruptedException 
+0

返信いただきありがとうございます。私はあなたの入力を取り込み、戻ってくるでしょう:) – user1708054

関連する問題