如何在 Hadoop-.20 api 中指定 KeyValueTextInputFormat 分隔符?
在新 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
相关文章