3

我想将输出分隔符更改为 ; 而不是标签。我已经尝试过: Hadoop:键和值在输出文件中是制表符分隔的。如何做到分号分隔? 但仍然是我的输出列表

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

作为我的输出。

4

3 回答 3

8

该属性称为mapreduce.output.textoutputformat.separator。所以你基本上错过了output那里。

您可以在 Apache SVN 中找到的最新主干源代码中看到这一点。

于 2013-05-17T18:55:46.570 回答
5

你应该conf.set("mapreduce.textoutputformat.separator", ";");

conf.set("mapreduce.textoutputformat.separator", ";"); 不推荐使用

mapredmapreduce

关联

完整代码:这是有效的。

    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;
于 2014-09-29T10:06:17.503 回答
5

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

我相信使用原生常量可以提供更好的可维护性和更少的惊喜。

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

于 2017-10-31T15:09:28.470 回答