2017-08-26 11 views
0

に私はMapReduceのに新しいですし、私はマッパークラスと減速クラス設計マッパーのクラスとリデューサークラスのMapReduceデザインパターン

に、このコードにいくつかの疑問を持っています:私たちはMapperクラスに私たちのクラスを拡張してマップ方法は入力として、このキーと値を取るようObjectがキーとTextあるとする値であることを学んだ上記のコードではここ

public static class CustsMapper extends Mapper<Object, Text, Text, Text> { 
     public void map(Object key, Text value, Context context) throws IOException, InterruptedException { 

contextオブジェクトはここでこのように出力としてcontext.write(new Text(), new Text())コードの論理本体の設計。

私の二つの質問は次のとおりです。

  1. 我々はMapReduceBaseに私たちのクラスを拡張してきたし、なぜ我々はMapperに私たちのクラスを実装しているのはなぜ(私はそれがクラスだ知っていたが、 ウェブで(それが何?)どこかのインターフェースとしての上映は、私がmap機能で org.apache.hadoop.mapreduce.Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT> クラスの問題は何ですか?

  2. にそれを拡張するので、もしOutputCollector<Text, IntWritable> output, Reporter reporter ??私はそれを知らなかったんでしょうか?私は知っていましたそのContext contextはここにあるはずですが、OutputCollectorReporter はここにありますか?私は下に与えられたこのプログラムをやっていた

に:

入力:

1979 23 23 2 43 24 25 26 26 26 26 25 26 25 
1980 26 27 28 28 28 30 31 31 31 30 30 30 29 
1981 31 32 32 32 33 34 35 36 36 34 34 34 34 
1984 39 38 39 39 39 41 42 43 40 39 38 38 40 
1985 38 39 39 39 39 41 41 41 00 40 39 39 45 

コード:

package hadoop; 

import java.util.*; 

import java.io.IOException; 
import java.io.IOException; 

import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.conf.*; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*; 
import org.apache.hadoop.util.*; 

public class ProcessUnits 
{ 
    //Mapper class 
    public static class E_EMapper extends MapReduceBase implements Mapper<LongWritable ,Text,Text,IntWritable>  
    {  
     //Map function 
     public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException 
     { 
     String line = value.toString(); 
     String lasttoken = null; 
     StringTokenizer s = new StringTokenizer(line,"\t"); 
     String year = s.nextToken(); 

     while(s.hasMoreTokens()) 
      { 
       lasttoken=s.nextToken(); 
      } 

     int avgprice = Integer.parseInt(lasttoken); 
     output.collect(new Text(year), new IntWritable(avgprice)); 
     } 
    } 


    //Reducer class 
    public static class E_EReduce extends MapReduceBase implements Reducer< Text, IntWritable, Text, IntWritable> 
    {  
     //Reduce function 
     public void reduce(Text key, Iterator <IntWritable> values, 
     OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException 
     { 
      int maxavg=30; 
      int val=Integer.MIN_VALUE; 

      while (values.hasNext()) 
      { 
       if((val=values.next().get())>maxavg) 
       { 
        output.collect(key, new IntWritable(val)); 
       } 
      } 

     } 
    } 


    //Main function 
    public static void main(String args[])throws Exception 
    { 
     JobConf conf = new JobConf(ProcessUnits.class); 

     conf.setJobName("max_eletricityunits"); 
     conf.setOutputKeyClass(Text.class); 
     conf.setOutputValueClass(IntWritable.class); 
     conf.setMapperClass(E_EMapper.class); 
     conf.setCombinerClass(E_EReduce.class); 
     conf.setReducerClass(E_EReduce.class); 
     conf.setInputFormat(TextInputFormat.class); 
     conf.setOutputFormat(TextOutputFormat.class); 

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

     JobClient.runJob(conf); 
    } 
} 

出力:(?それは何をするか)

1981 34 
1984 40 
1985 45 
+0

が 'mapred *;'古いAPIクラスですhttps://stackoverflow.com/questions/16269922/hadoop-mapred-vs-hadoop-mapreduce –

+0

OutputCollectorは古い方法ですコンテキスト。write –

+0

親愛なる@ cricket_007 Okですが、OutputCollectorとReporterは何ですか? 'org.apache.hadoop.mapreduce。*'のように動作しますか?古いAPIですか?右? –

答えて

0

我々はMapReduceBaseに私たちのクラスを拡張してきたし、それがmapredと書かれた古いコードなので、なぜ我々は

をマッパーために私たちのクラスを実装しているのはなぜHadoop 2.xが登場する前のAPI

私はそのコンテキストのコンテキストは、ここでする必要があります知っていたが、OutputCollectorは何であるとレポーターここ

これは、Contextオブジェクトの以前のバージョンです。

Hadoop: How does OutputCollector work during MapReduce?
How outputcollector works?

+0

ありがとう私の親愛なる友人。 –

関連する問題