我只想输出值,所以我使用NullWritable作为OutputKeyClass,如下所示:
protected void reduce(Text key, Iterable<Text> values,
Reducer<Text, Text, NullWritable, Text>.Context context)
throws IOException, InterruptedException {
for(Text value : values){
context.write(NullWritable.get(), value);
}
}我的作业设置如下:
job.setNumReduceTasks(1);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(baseInPath));
FileSystem.get(conf).delete(new Path(baseOutPath), true);
FileOutputFormat.setOutputPath(job, new Path(baseOutPath));
System.exit(job.waitForCompletion(true) ? 0 : 1);但是当我检查结果路径时,我得到了这个。�LZO
` @��V��/�!�Z0|res|1*"|33260580217607|2|1|0.2|23|2016-03-28 13:57:42 0|pay 6-03-28 13:57:42
字符串以0|res|1……开头是价值,但前面有一些乱码。我认为他们是NullWritable的指针。我怎样才能去除这些乱码?我的代码是正确的吗?
发布于 2016-03-29 14:10:00
从输出看,似乎设置了LZO压缩。您可以尝试查看mapred-site.xml并查看是否设置了此属性
<property>
<name>mapred.map.output.compression.codec</name>
<value>com.hadoop.compression.lzo.LzoCodec</value>
</property>有关更多细节,请访问:link
https://stackoverflow.com/questions/36275902
复制相似问题