Java Hadoop-输出键/值分隔符

Java Hadoop-输出键/值分隔符,java,hadoop,separator,Java,Hadoop,Separator,我想将输出分隔符更改为;而不是标签。我已经试过了: 但我的输出仍然是错误的 key (tab) value 我正在使用Cloudera演示(CDH 4.1.3)。 这是我的密码: Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length !=

我想将输出分隔符更改为;而不是标签。我已经试过了: 但我的输出仍然是错误的

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;

作为我的输出。

该属性称为
mapreduce.output.textoutputformat.separator
。 因此,您基本上缺少那里的
输出

您可以看到,在最新的主干源代码中,您应该
conf.set(“mapreduce.textoutputformat.separator”,“;”

使用
conf.set(“mapreduce.textoutputformat.separator”、“;”)已弃用

mapred
mapreduce

完整代码:这是工作

    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;
Configuration conf=new Configuration();
String[]otherArgs=新的GenericOptionsParser(conf,args);
if(otherArgs.length!=2){
System.err.println(“用法:驱动程序”);
系统出口(2);
}
conf.set(“mapred.textoutputformat.separator”、“;”);
路径输入=新路径(其他参数[0]);
路径输出=新路径(其他参数[1]);
Job Job=新作业(getConf());
job.setJobName(“MapReduce”);
setMapperClass(Mapper.class);
job.setReducerClass(Reducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
setInputFormatClass(TextInputFormat.class);
setOutputFormatClass(TextOutputFormat.class);
setInputPath(作业,在中);
setOutputPath(作业,输出);
job.setJarByClass(Driver.class);
作业。等待完成(true)?0 : 1;

2019年,它是
getConf().set(TextOutputFormat.SEPARATOR,;”(谢谢@AsheshKumarSingh)

我相信,使用本机常量可以提供更好的可维护性和更少的意外


重要提示:此属性必须在Job.getInstance(getConf())
/
新作业(getConf())
之前设置,因为作业复制参数,不关心进一步修改conf。

@JustTheAverageGirl=Hadoop 2.0(这是CDH4中的默认值)已经用mapreduce.*@ChrisWhite替换了很多mapreduce.*属性
mapreduce
属性只是表示应该替换旧的
mapreduce
属性的较新API。现在,这两个都仍然可用,没有一个被弃用。我只是想澄清一下,
mapreduce
不是Hadoop 2.0或Thread(我想你知道;)的标志。是的,但我要指出的是,这个属性在v1[第115行]和v2之间有变化[第45行--设置前缀的同一类、不同属性xi尝试了mapreduce.output.textoutputformat.separator,但仍然没有;作为分隔符。@ThomasJungblut:它是conf.set(“mapred.textoutputformat.separator”,“;”;而不是conf.set(“mapreduce.textoutputformat.separator”,“;”)).mapred和mapreduce玩了这个游戏。看到了吗:Hadoop代码中的常量拼错了。它是
SEPARATOR
,正如@Nikita Bosik在2019年10月写的,它的
TextOutputFormat.SEPARATOR
    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;