を減らして2つのファイルの内容を参加:は
最初のファイル(従業員名のデータを含む)
id,name
101,Gaurav
102,Rohit
103,Karishma
104,Darshan
105,Divya
セカンドファイルを(従業員部門のデータを含む)
id,dept
101,Sales
102,Research
103,NMG
104,Admin
105,HR
=====================
私は、出力のこの種をacheiveするにはどうすればよいです出力
id,name,dept
101,Gaurav,Sales
102,Rohit,Research
103,Karishma,NMG
?今私は、減速中にランダムな値などのアウトを取得していますのよう
..
私は、ID、名前、部署などの指定された順序で出力したいです。 助けていただければ幸いです。
マッパークラスは次のようになります...
public class JoinMapper extends Mapper<LongWritable, Text, Text, Text> {
private Text keyEmit = new Text();
private Text valEmit = new Text();
public void map(LongWritable k, Text value, Context context) throws IOException, InterruptedException
{
String line=value.toString();
String[] words=line.split(",");
keyEmit.set(words[0]);
valEmit.set(words[1]);
context.write(keyEmit, valEmit);
}
}
リデューサークラスは次のようになります...
public class JoinReducer extends Reducer<Text, Text, NullWritable, Text> {
String merge = "";
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
merge = key.toString(); // 101
for(Text value : values) {
merge += "," + value.toString();
}
context.write(NullWritable.get(), new Text(merge));
}
}
ドライバーのクラス次のようになります...
public class JoinDriver {
public final static void main(final String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "Multiple join");
job.setJarByClass(JoinDriver.class);
// job.setMapperClass(JoinMapper.class);
job.setReducerClass(JoinReducer.class);
MultipleInputs.addInputPath(job, new Path(args[0]),
TextInputFormat.class, JoinMapper.class);
MultipleInputs.addInputPath(job, new Path(args[1]),
TextInputFormat.class, JoinMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileOutputFormat.setOutputPath(job, new Path(args[2]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
出力は次のようになります。私はid、name、departmentの順番でそれを望みます。
質問にはコードを入力する必要があります。 –
@BinaryNerdコードをチェックしてください。私が知っておくべきことは、減速機への入力として送信される値がランダムであること、この特定の場合に特定の順序で送信する方法です。 –