Java を使用して Hadoop Map/Reduce を使用しています
map/reduce ジョブ全体を完了したとします。仕事を終了せずに、マップ全体/リデュース部分のみを繰り返す方法はありますか? つまり、さまざまなジョブのチェーンを使用したくないのですが、マップ/リデュースの部分だけを繰り返したいだけです。
ありがとうございました!
したがって、私は Hadoop ストリーミング API に精通していますが、アプローチはネイティブ API に変換する必要があります。
私の理解では、あなたがやろうとしていることは、入力データに対して同じ map() および reduce() 操作を何度か繰り返し実行することです。
最初の map() 入力データがファイル input.txt から取得され、出力ファイルが output + {iteration}.txt (反復はループ回数、反復 =[0、反復回数)) であるとします。map()/reduce() の 2 回目の呼び出しでは、入力ファイルは output+{iteration} になり、出力ファイルは output+{iteration +1}.txt になります。
これが明確でない場合はお知らせください。簡単な例を思いついて、ここにリンクを投稿できます。
EDIT * Javaの場合、hadoopのwordcountの例を複数回実行するように変更しました
package com.rorlig;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCountJob {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
if (args.length != 3) {
System.err.println("Usage: wordcount <in> <out> <iterations>");
System.exit(2);
}
int iterations = new Integer(args[2]);
Path inPath = new Path(args[0]);
Path outPath = null;
for (int i = 0; i<iterations; ++i){
outPath = new Path(args[1]+i);
Job job = new Job(conf, "word count");
job.setJarByClass(WordCountJob.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, inPath);
FileOutputFormat.setOutputPath(job, outPath);
job.waitForCompletion(true);
inPath = outPath;
}
}
}
お役に立てれば