避免在mapreduce作业输出文件的结尾追加part-r-00***

btqmn9zl  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(421)

我正在使用multioutputformat类运行mr代码。第****部分将附加到我的输出文件的末尾。我怎样才能避免呢?
公共类mr\u reducer扩展reducer{

private MultipleOutputs multipleOutputs;

@Override
protected void setup(Context context) throws IOException,
        InterruptedException {
    multipleOutputs = new MultipleOutputs(context);
}

@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
    for (Text value : values) {
        multipleOutputs.write(value, new Text(""), key.toString());
    }
}

@Override
protected void cleanup(Context context) throws IOException,
        InterruptedException {
    multipleOutputs.close();
}

}

3phpmpom

3phpmpom1#

这个代码片段在我这里工作。你没有什么不同:

public static class Reduce extends Reducer<Text, Text, NullWritable, Text> {

    private MultipleOutputs<NullWritable, Text> multipleOutputs;

    protected void setup(Context context) throws IOException, InterruptedException {
        multipleOutputs = new MultipleOutputs<NullWritable, Text>(context);

    }

    public void reduce(Text key, Iterable<Text> values, Context output) throws IOException, InterruptedException {
        while (values.iterator().hasNext()) {
            multipleOutputs.write(NullWritable.get(), values.iterator().next(), key.toString());
        }
    }

    protected void cleanup(Context context) throws IOException, InterruptedException {
        multipleOutputs.close();
    }
}

相关问题