2017-09-24 7 views
2

私はカスタムコンバイナーを使用していますが、無視される可能性がありますか?

job.setMapperClass(AverageIntMapper.class); 
    job.setCombinerClass(AverageIntCombiner.class); 
    job.setReducerClass(AverageIntReducer.class); 

...メインでこれを持っており、コンバイナは異なるコードを持っていますが、減速が使用している出力は、マッパーから出力されるようコンバイナは完全に無視されています。

私はコンバイナーが使用できないことを理解しますが、コンビネーターがリデューサーと同じであると考えました。私はカスタムコンバイナを作成できるという点を本当に理解していませんが、システムは引き続きその使用法をスキップできます。

これが起こらなければ、コンバイナが使用されていない理由は何でしょうか?

コード...あなたが見れば

import java.io.IOException; 

import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.DoubleWritable; 
import org.apache.hadoop.io.LongWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Job; 
import org.apache.hadoop.mapreduce.Mapper; 
import org.apache.hadoop.mapreduce.Reducer; 
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 


public class AverageInt { 

public static class AverageIntMapper extends Mapper<LongWritable, Text, Text, Text> { 

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

     String n_string = value.toString(); 
     context.write(new Text("Value"), new Text(n_string)); 
    } 
} 

public static class AverageIntCombiner extends Reducer<Text, Text, Text, Text> { 

    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { 

     int sum = 0; 
     int count = 0; 

     for(IntWritable value : values) { 
      int temp = Integer.parseInt(value.toString()); 
      sum += value.get(); 
      count += 1; 
     } 

     String sum_count = Integer.toString(sum) + "," + Integer.toString(count); 

     context.write(key, new Text(sum_count)); 
    } 
} 

public static class AverageIntReducer extends Reducer<Text, Text, Text, Text> { 

    public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { 

     int total = 0; 
     int count = 0; 

     for(Text value : values) { 
      String temp = value.toString(); 
      String[] split = temp.split(","); 
      total += Integer.parseInt(split[0]); 
      count += Integer.parseInt(split[1]); 
     } 

     Double average = (double)total/count; 

     context.write(key, new Text(average.toString())); 
    } 
} 

public static void main(String[] args) throws Exception { 

    if(args.length != 2) { 
     System.err.println("Usage: AverageInt <input path> <output path>"); 
     System.exit(-1); 
    } 

    Job job = new Job(); 
    job.setJarByClass(AverageInt.class); 
    job.setJobName("Average"); 

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

    job.setMapperClass(AverageIntMapper.class); 
    job.setCombinerClass(AverageIntCombiner.class); 
    job.setReducerClass(AverageIntReducer.class); 

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

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

を無視している知っていますか?コンバイナのカウントはありませんか? –

+0

@BinaryNerd Combinerで作成される値には、Reducerで分割しようとするデリミタがありますが、分割しようとすると配列外のエラーが発生します。私がReducerで分割するロジックを削除して、それが入力として取得している値を出力するだけの場合、Mapperが出力しているものです。 – cpd1

+0

あなたのコードを投稿します。そうでなければ誰もあなたを助けることができません。 –

答えて

1

何あなたのマッパーが放出されています

public void map(LongWritable key, Text value, Context context)

そのあなたがコンバイナクラス自体に宣言しましたが、一方で2つのTextオブジェクトを送信正しく、reduceメソッドは次のようになります。

public void reduce(Text key, Iterable<IntWritable> values, Context context)

それは次のようになります。どのようにしてその

public void reduce(Text key, Iterable<Text> values, Context context)

+0

問題を修正したようです。私はコンパイル/実行時にエラーがなかったので、私はこの問題に気付かなかったと思います。 – cpd1

+0

これは簡単な間違いですが、hadoopはReduceクラスのベース実装を使用していますが、これを変更せずにデータを渡すだけです。 –

関連する問題