如何在Hadoop-20 api中指定KeyValueTextInputFormat分隔符? [英] How to specify KeyValueTextInputFormat Separator in Hadoop-.20 api?

查看:270
本文介绍了如何在Hadoop-20 api中指定KeyValueTextInputFormat分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的API(apache.hadoop.mapreduce.KeyValueTextInputFormat)中,如何指定分隔符(分隔符)而不是tab(默认值)来分隔键和值。



样本输入:

  one,first line 
two,second line

需要输出:

 键:一个
值:第一行
键:两个
值:第二行

我将KeyValueTextInputFormat指定为:

  Job job = new Job(conf,Sample); 

job.setInputFormatClass(KeyValueTextInputFormat.class);
KeyValueTextInputFormat.addInputPath(job,new Path(/ home / input.txt));

这对于标签作为分隔符来说工作得很好。

解决方案

在较新的API中,您应该使用 mapreduce.input.keyvaluelinerecordreader.key.value.separator 配置属性。

  Configuration conf = new Configuration(); 
conf.set(mapreduce.input.keyvaluelinerecordreader.key.value.separator,,);

工作职位=新职位(conf);
job.setInputFormatClass(KeyValueTextInputFormat.class);
//下一个工作设置


In new API (apache.hadoop.mapreduce.KeyValueTextInputFormat) , how to specify separator (delimiter) other than tab(which is default) to separate key and Value.

Sample Input :

one,first line
two,second line

Ouput Required :

Key : one
Value : first line
Key : two
Value : second line

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.

解决方案

In the newer API you should use mapreduce.input.keyvaluelinerecordreader.key.value.separator configuration property.

Here's an example:

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分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆