2016-06-26 5 views
0

私はMapReduceプログラムを使って、フォルダとそのサブフォルダからファイルを再帰的に読み込みます。私はカスタムファイル入力フォーマットクラスを作成してisSplitableをfalseにして、1つのフルファイルが1つのマッパーのみになり、ファイルを1行ずつ読み込むようにしました。私はパターンを探しているので、一致が見つかれば、私は続行したくないし、現在のファイルの実行をスキップしたい。どのようにマッパークラスでそれを達成できますか?MapReduceのMapperから現在処理中のファイルをスキップする方法

答えて

0

runメソッドを単純に実装することができます。たとえば、このように、クリーンアップフェーズに直接短絡するブールフィールドがあります。

public class SkipMapper extends Mapper<LongWritable, Text, Text, Text> { 

    private boolean skip; 

    @Override 
    protected void map(LongWritable key, Text value, 
     Mapper<LongWritable, Text, Text, Text>.Context context) 
     throws IOException, InterruptedException { 

    // map with the matcher 
    if (match) { 
     skip = true; 
    } 

    } 

    @Override 
    public void run(Mapper<LongWritable, Text, Text, Text>.Context context) 
     throws IOException, InterruptedException { 
    setup(context); 
    try { 
     while (!skip && context.nextKeyValue()) { 
     map(context.getCurrentKey(), context.getCurrentValue(), context); 
     } 
    } finally { 
     cleanup(context); 
    } 
    } 

} 
+0

ありがとう、トーマス、これは本当に役に立ちます... –

関連する問題