に私は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())
コードの論理本体の設計。
私の二つの質問は次のとおりです。
我々は
MapReduceBase
に私たちのクラスを拡張してきたし、なぜ我々はMapper
に私たちのクラスを実装しているのはなぜ(私はそれがクラスだ知っていたが、 ウェブで(それが何?)どこかのインターフェースとしての上映は、私がmap
機能でorg.apache.hadoop.mapreduce.Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
クラスの問題は何ですか?にそれを拡張するので、もし
OutputCollector<Text, IntWritable> output, Reporter reporter
??私はそれを知らなかったんでしょうか?私は知っていましたそのContext context
はここにあるはずですが、OutputCollector
とReporter
はここにありますか?私は下に与えられたこのプログラムをやっていた
に:
入力:
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
が 'mapred *;'古いAPIクラスですhttps://stackoverflow.com/questions/16269922/hadoop-mapred-vs-hadoop-mapreduce –
OutputCollectorは古い方法ですコンテキスト。write –
親愛なる@ cricket_007 Okですが、OutputCollectorとReporterは何ですか? 'org.apache.hadoop.mapreduce。*'のように動作しますか?古いAPIですか?右? –