在新 API (apache.hadoop.mapreduce.KeyValueTextInputFormat) 中,如何指定制表符(默认)以外的分隔符(分隔符)来分隔键和值.
In new API (apache.hadoop.mapreduce.KeyValueTextInputFormat) , how to specify separator (delimiter) other than tab(which is default) to separate key and Value.
示例输入:
one,first line
two,second line
需要输出:
Key : one
Value : first line
Key : two
Value : second line
我将 KeyValueTextInputFormat 指定为:
I am specifying KeyValueTextInputFormat as :
Job job = new Job(conf, "Sample");
job.setInputFormatClass(KeyValueTextInputFormat.class);
KeyValueTextInputFormat.addInputPath(job, new Path("/home/input.txt"));
这对于作为分隔符的制表符来说效果很好.
This is working fine for tab as a separator.
在较新的 API 中,您应该使用 mapreduce.input.keyvaluelinerecordreader.key.value.separator
配置属性.
In the newer API you should use mapreduce.input.keyvaluelinerecordreader.key.value.separator
configuration property.
这是一个例子:
Configuration conf = new Configuration();
conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator", ",");
Job job = new Job(conf);
job.setInputFormatClass(KeyValueTextInputFormat.class);
// next job set-up
这篇关于如何在 Hadoop-.20 api 中指定 KeyValueTextInputFormat 分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!