如何将化简器中的输出文件名从 part-00000 更改为输入文件名



目前,我可以在映射器中实现从part-00000到自定义文件名的名称更改。我是通过采取inputSplit来做到这一点的.我在化简器中尝试了相同的方法来重命名文件,但是,文件拆分方法不适用于化简器。那么,是否有一种最好的方法可以使用输入文件名将化简器的输出重命名为。以下是我在映射器中实现它的方式。

@Override
    public void setup(Context con) throws IOException, InterruptedException {
        fileName = ((FileSplit) con.getInputSplit()).getPath().getName();
        fileName = fileName.substring(0,36);
        outputName = new Text(fileName);  
        final Path baseOutputPath = FileOutputFormat.getOutputPath(con);
        final Path outputFilePath = new Path(baseOutputPath, fileName);
        TextOutputFormat<IntWritable, Text> write = new TextOutputFormat<IntWritable, Text>() {
        @Override
        public Path getDefaultWorkFile(TaskAttemptContext context, String extension) throws IOException {
        return outputFilePath;

这是Hadoop维基所说的:

You can subclass the OutputFormat.java class and write your own. You can locate and browse the code of TextOutputFormat, MultipleOutputFormat.java, etc. for reference. It might be the case that you only need to do minor changes to any of the existing Output Format classes. To do that you can just subclass that class and override the methods you need to change. 

如果您需要使用键和输入文件格式,则可以创建MultipleOutputFormat的子类来控制输出文件名。

最新更新