【问题标题】:Remove -r-00000 on Reducer output删除 Reducer 输出上的 -r-00000
【发布时间】:2017-10-20 16:09:06
【问题描述】:

我正在使用这样的 MultipleOutputs:

public int run(String[] args) throws Exception {
        ...
        job1.setInputFormatClass(TextInputFormat.class);
        job1.setOutputFormatClass(TextOutputFormat.class);          

        ****MultipleOutputs.addNamedOutput(job1, "stopwords", TextOutputFormat.class, Text.class, IntWritable.class);****
        ...
}

在减速器上

public static class ReduceWordCount extends Reducer<Text, IntWritable, Text, IntWritable> {  
    private MultipleOutputs<Text, IntWritable> mos;
    @Override
    public void setup(Context context) {
         mos = new MultipleOutputs<Text, IntWritable>(context);
    }
    @Override
    public void reduce(Text word, Iterable<IntWritable> counts, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable count : counts) {
            sum += count.get();
        }
        if(sum>4000){
            context.write(word, new IntWritable(sum));
            mos.write("stopwords", new Text(word+", "), sum, "stopwords.csv");
        }
    }
    protected void cleanup(Context context) throws IOException, InterruptedException {
        mos.close();
    }
}

我得到的输出文件是 stopwords.csv-r-00000 我需要摆脱-r-00000。我怎样才能做到这一点?

【问题讨论】:

  • 你有多少个减速器?如果你有超过 1 个 reducer,而你没有 -r-00000 段,它将失败

标签: java hadoop mapreduce multipleoutputs


【解决方案1】:

我找到了一个答案here 可能关心的人,他在工作完成后重命名了文件

    FileSystem hdfs = FileSystem.get(getConf());
    FileStatus fs[] = hdfs.listStatus(new Path(args[1]));
    if (fs != null){ 
    for (FileStatus aFile : fs) {
        if (!aFile.isDir()) {
            hdfs.rename(aFile.getPath(), new Path(aFile.getPath().toString()+".txt"));
        }
    }
}

【讨论】:

    猜你喜欢
    • 2016-08-05
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2016-09-10
    相关资源
    最近更新 更多