出力を実現するにはさまざまな方法がありますが、パーティショナーとのやり取りについて言及しているので、これでやりましょう。
あなたの質問によると、「Term」(iphone、Galaxyなど)の出力を分割したいキーベースのパーティションを作成する必要があります。マップ出力のキー形式と値の形式それに応じて変更されなければテキストです。これは、あなたのパーティが
public class Partitioners extends org.apache.hadoop.mapreduce.Partitioner<Text,Text>{
// I have the written the code if there are 3 reducer(since you have 3 type of key).
//Tip: your number of reducers should be equal to the no of batches you want to divide your map output into.
@Override
public int getPartition(Text key, Text value, int numReduceTasks) {
String Skey = key.toString();
//Again make changes according to your requirement here but I think it will work according to the composite key you have mentioned
String term = Skey.substring(0, Skey.indexOf(':'));
if(term.equals("Iphone"))
{ // this will send all the key having iphone in reducer 1
return 0;
}else if(term.equals("Galaxy"))
{ // this will send all the key having Galaxy in reducer 2
return 1;
}
else{
// this will send all the key having other then Iphone and galaxy which is Htc in your case in reducer 3
return 2;
}
}
}
どのように見えるかでパーティが行われた後、今、私たちはこれについて、当社のドライバクラスを通知する必要がありますので、あなたのドライバのクラスに
job.setPartitionerClass(Partitioners.class);
job.setNumReduceTasks(3); //since we want 3 reducers
を以下を追加しますこれはであなたのマップの出力を分割します3パーティショナーを使用すると、減速機クラスで出力を減らすことができます。
これがあなたの問題を解決することを願っています。もし私に知らせてくれないなら。
コード出力の例 - マッパーの出力は? –
@siddharthajain no還元剤からの出力「最終出力」 – user5532529
マップ出力のキーとそのフォーマットは何ですか? –