2012-03-14 6 views
1

少なくとも10回発生した単語を出力するために、以下のコードを修正しました。しかし、それは動作しません - 出力ファイルはまったく変更されません。それを動作させるためには何が必要ですか?Hadoopの単語数からの予期しない出力

import java.io.IOException; 
import java.util.*; 

import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.conf.*; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapreduce.*; 
import org.apache.hadoop.mapreduce.lib.input.*; 
import org.apache.hadoop.mapreduce.lib.output.*; 
import org.apache.hadoop.util.*; 
// ... 
public class WordCount extends Configured implements Tool { 
// ... 
public static class Map 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); 
     } 
    } 
} 

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; 
     for (IntWritable val : values) { 
      sum += val.get(); 
     } 
        // where I modified, but not working, the output file didnt change 
     if(sum >= 10) 
     { 
      context.write(key, new IntWritable(sum)); 
     } 
    } 
} 

public int run(String[] args) throws Exception { 
    Job job = new Job(getConf()); 
    job.setJarByClass(WordCount.class); 
    job.setJobName("wordcount"); 

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

    job.setMapperClass(Map.class); 
    //job.setCombinerClass(Reduce.class); 
    job.setReducerClass(Reduce.class); 

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

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

    boolean success = job.waitForCompletion(true); 
    return success ? 0 : 1; 
} 

public static void main(String[] args) throws Exception { 
    int ret = ToolRunner.run(new WordCount(), args); 
    System.exit(ret); 
} 
} 

答えて

1

コードは完全に有効です。私はあなたのデータセットが十分に大きいと疑うことができるので、言葉は10回以上現れますか? 実際に新しい結果が得られていることを確認してください。

0

デフォルトのHadoopカウンタが表示され、何が起きているのかがわかります。

+0

までこの

one two two three three three 

その他、各種アップのようなファイルを送る場合は減らす入力グループの数が削減出力レコードの数に等しい場合は、実際の出力を投稿することができればそれも役立つだろう、すべての出力が> = 10であることを確認した場合、これは@Davidによって残されたコメントをサポートします –

0

コードは間違いなく正しいです。コードを変更する前に生成された出力を読み込んでいる可能性があります。あるいは、以前にコードを修正した後に使用したjarファイルを更新しなかったのでしょうか?

0

コードは有効です。 少なくともこれを実行するために使用したコマンドラインが必要です。あなたが具体的にそれを20