2013-05-17 41 views
1

我想将输出分隔符更改为;而不是标签。我已经尝试过: Hadoop: key and value are tab separated in the output file. how to do it semicolon-separated? 但是我的输出ISTHadoop - 输出键/值分隔符

key (tab) value 

我使用Cloudera的演示(CDH 4.1.3)。 这里是我的代码:

Configuration conf = new Configuration(); 
     String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); 
     if (otherArgs.length != 2) { 
      System.err.println("Usage: Driver <in> <out>"); 
      System.exit(2); 
     } 
     conf.set("mapreduce.textoutputformat.separator", ";"); 

     Path in = new Path(otherArgs[0]); 
     Path out = new Path(otherArgs[1]); 

     Job job= new Job(getConf()); 
     job.setJobName("MapReduce"); 

     job.setMapperClass(Mapper.class); 
     job.setReducerClass(Reducer.class); 

     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(Text.class); 

     job.setInputFormatClass(TextInputFormat.class); 
     job.setOutputFormatClass(TextOutputFormat.class); 

     FileInputFormat.setInputPaths(job, in); 
     FileOutputFormat.setOutputPath(job, out); 

     job.setJarByClass(Driver.class); 
     job.waitForCompletion(true) ? 0 : 1; 

我想

key;value 

我的输出。

+1

看到这个:http://www.unmeshasreeveni.blogspot.in/2014/04/can-we-change-default-key-value-output.html –

回答

7

该物业被称为mapreduce.output.textoutputformat.separator。 所以你基本上在那里缺少output

你可以看到,在最新的主干源代码found in the Apache SVN.

+0

@JustTheAverageGirl = Hadoop 2.0又名YARN(这是默认在CDH4中)已经用mapreduce取代了很多mapred。*属性。* –

+0

@ChrisWhite'mapreduce'属性只是表示更新的API,它应该替代旧的'mapred'。如今,两者仍然可用,没有一个被弃用。只是想澄清'mapreduce'对于Hadoop 2.0或YARN(我猜你知道;))没有任何标志。 –

+0

是的,但是我指出这个属性在v1 [line 115 - http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.2/src/mapred/org/apache/hadoop /mapreduce/lib/output/TextOutputFormat.java?view=markup]和v2 [第45行 - http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client /hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/output/TextOutputFormat.java?view=markup] - 相同的类,不同的属性来设置前缀 –

3

您应该使用conf.set("mapred.textoutputformat.separator", ";");代替conf.set("mapreduce.textoutputformat.separator", ";");

mapredmapreduce

Link

全码:这是工作。

Configuration conf = new Configuration(); 
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); 
    if (otherArgs.length != 2) { 
     System.err.println("Usage: Driver <in> <out>"); 
     System.exit(2); 
    } 
    conf.set("mapred.textoutputformat.separator", ";"); 

    Path in = new Path(otherArgs[0]); 
    Path out = new Path(otherArgs[1]); 

    Job job= new Job(getConf()); 
    job.setJobName("MapReduce"); 

    job.setMapperClass(Mapper.class); 
    job.setReducerClass(Reducer.class); 

    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(Text.class); 

    job.setInputFormatClass(TextInputFormat.class); 
    job.setOutputFormatClass(TextOutputFormat.class); 

    FileInputFormat.setInputPaths(job, in); 
    FileOutputFormat.setOutputPath(job, out); 

    job.setJarByClass(Driver.class); 
    job.waitForCompletion(true) ? 0 : 1; 
+1

Downvoters请发表评论 –

1

在2017年,它是getConf().set(TextOutputFormat.SEPERATOR, ";");

使用本机不断提供更好的可维护性和更少的惊喜,我相信。

重要:此属性必须设置Job.getInstance(getConf())/new Job(getConf())之前,作为工作拷贝参数,并且不关心进一步的conf修改。

+0

常量在Hadoop代码中拼写错误。它就像@Nikita Bosik写道的那样是'SEPERATOR' –