嗨,我的 reducer 无法打印出理想的结果,请看一下代码。
这是我的 map 功能
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
{
String str_line = value.toString();
Detail_output1_column_array = str_line.split("\\"+tabSpace);
Outputkey = Detail_output1_column_array[2];
System.out.println(Outputkey);
context.write(new Text(Outputkey),NullWritable.get());
}
}
public static class ShopFile_Reducer extends Reducer<Text,Iterable<NullWritable>,NullWritable,Text> {
public void reduce(Text Key,Iterable<NullWritable> Values,Context context) throws IOException, InterruptedException {
Key = new Text(Key.toString());
context.write(NullWritable.get(),new Text(Key));
}
}
假设Detail_output1_column_array [2]包含
01
01
01
02
01
02
01
03
01
reducer 后,我需要这样的输出
01
02
03
但是它正在打印所有东西
01
01
01
02
01
02
01
03
01
这是我的司机课
Configuration Shopconf = new Configuration();
Shopconf.setStrings("DTGroup_input",DTGroup_input);
Job Shop = new Job(Shopconf,"Export_Column_Mapping");
Shop.setJarByClass(ExportColumnMapping.class);
Shop.setJobName("ShopFile_Job");
Shop.setMapperClass(ShopFile_Mapper.class);
Shop.setReducerClass(ShopFile_Reducer.class);
Shop.setInputFormatClass(TextInputFormat.class);
Shop.setOutputFormatClass(TextOutputFormat.class);
Shop.setMapOutputKeyClass(Text.class);
Shop.setMapOutputValueClass(NullWritable.class);
Shop.setOutputKeyClass(Text.class);
Shop.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(Shop, new Path(outputpath+"/Detailsfile/part*"));
FileOutputFormat.setOutputPath(Shop, new Path(outputpath+"/Shopfile"));
Shop.waitForCompletion(true);
最佳答案
在您的映射器代码中
使用此Outputkey.set( Detail_output1_column_array[2]);
代替Outputkey = Detail_output1_column_array[2];
关于hadoop - Reducer在Hadoop Mapreduce中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33516571/