2012-04-26 11 views
1

私の出力には重複した値がたくさんあるので、以下に示すようにreduce関数を実装しましたが、このreduceはID関数として機能します。つまり、reduceをしても出力に違いはありません。 reduce関数の問題は何ですか?mapreduceプログラムの出力に重複がありますか?

 public class search 
{  
    public static String str="And"; 
    public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text> 
    { 
     String mname=""; 
     public void configure(JobConf job) 
     { 
      mname=job.get(str); 
      job.set(mname,str); 
     } 

     private Text word = new Text(); 
     public Text Uinput =new Text(""); 
     public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
     { 

      String mapstr=mname; 
      Uinput.set(mapstr); 
      String line = value.toString(); 
      Text fdata = new Text(); 

      StringTokenizer tokenizer = new StringTokenizer(line); 
      while (tokenizer.hasMoreTokens()) 
      { 
       word.set(tokenizer.nextToken()); 
       fdata.set(line); 

       if(word.equals(Uinput)) 
       output.collect(fdata,new Text("")); 
      } 

     } 
    } 

    public static class SReducer extends MapReduceBase implements Reducer<Text, Text, Text, Text> 
    { 
     public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
     { 

      boolean start = true; 
      //System.out.println("inside reduce :"+input); 
      StringBuilder sb = new StringBuilder(); 
      while (values.hasNext()) 
      { 
       if(!start) 

       start=false; 
       sb.append(values.next().toString()); 

      } 
      //output.collect(key, new IntWritable(sum)); 
      output.collect(key, new Text(sb.toString())); 
     } 
    } 

のpublic static無効メイン(文字列[] args)実際には、使用する機能を減らすよう {

JobConf conf = new JobConf(search.class); 
    conf.setJobName("QueryIndex"); 
    //JobConf conf = new JobConf(getConf(), WordCount.class); 
    conf.set(str,args[0]); 

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

    conf.setMapperClass(Map.class); 
    //conf.setCombinerClass(SReducer.class); 
    conf.setReducerClass(SReducer.class); 

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



    FileInputFormat.setInputPaths(conf, new Path("IIndexOut")); 
    FileOutputFormat.setOutputPath(conf, new Path("searchOut")); 

    JobClient.runJob(conf); 
} 

}

+0

可能な重複:http://stackoverflow.com/questions/10305435/hadoop-inverted-index-without-recurrence-of-file-names –

+0

こんにちはマット、私はそのポストを通過しましたが、それは私の問題を解決しませんでした。だから私は自分自身を投稿した。 –

答えて

0

たぶん、あなたはこの減速を設定していない例外がスローされますか?あなたはデフォルトの減速が使用されている、あなたのクラスとしてクラスを設定しない場合はそれは

job.setReducerClass(). 

を使用して行われます。以下を実行する必要があります。

job.setReducerClass(SReducer.class) 

私たちが確認できるように、あなたの主な機能を投稿してください。

+0

私はそれをしました、私も上に掲載しました、それを確認してください。 –

+0

あなたは最新の出力をお読みになりますか?以前のすべての出力ファイルを削除してジョブを再実行することをお勧めします。 btwであなたの仕事は何をしていますか? – Chaos

+0

その検索エンジンプログラムなので、indexoutは逆索引実装の出力です。この検索手順では、キーワードを検索して結果を表示するだけです( –

1

私は徹底的にコードを見ていないが、私はおよそ確信して一つのことは、ブール変数ではを開始場合は、ここで次のコード無用である(!スタート)デには、括弧内にする必要がありますそれ以外の場合は、マッパーから受け取った減速機のすべてのデータを書き込むだけです。あなただけのイテレータの第一値を気にしたよう

public static class SReducer extends MapReduceBase implements Reducer<Text, Text, Text, Text> 
    { 
    public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
{ 

    //System.out.println("inside reduce :"+input); 
    StringBuilder sb = new StringBuilder(); 
    sb.append(values.next().toString()); 

    //output.collect(key, new IntWritable(sum)); 
    output.collect(key, new Text(sb.toString())); 
} 

}

- :

public static class SReducer extends MapReduceBase implements Reducer<Text, Text, Text, Text> 
{ 
    public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
    { 

     boolean start = true; 
     //System.out.println("inside reduce :"+input); 
     StringBuilder sb = new StringBuilder(); 
     while (values.hasNext()) 
     { 
      if(!start) 
      { 
       start=false; 
       sb.append(values.next().toString()); 
      } 

     } 
     //output.collect(key, new IntWritable(sum)); 
     output.collect(key, new Text(sb.toString())); 
    } 
} 

または最適な削減方法はただになります。

0

マップの前に@overrideアノテーションを使用して関数を減らします。あなたが基本クラスのメソッドをオーバーライドしていることを確かめることができます。

関連する問題