Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将reducer中的输出文件名从part-00000更改为inputfile name_Java_Hadoop2 - Fatal编程技术网

Java 如何将reducer中的输出文件名从part-00000更改为inputfile name

Java 如何将reducer中的输出文件名从part-00000更改为inputfile name,java,hadoop2,Java,Hadoop2,目前,我能够在mapper中实现从part-00000到自定义文件名的名称更改。我通过使用inputSplit来实现这一点。我在reducer中尝试了相同的方法来重命名文件,但fileSplit方法不适用于reducer。那么,有没有最好的方法将reducer的输出重命名为inputfile name呢。下面是我如何在mapper中实现它的 @Override public void setup(Context con) throws IOException, InterruptedEx

目前,我能够在mapper中实现从
part-00000
到自定义文件名的名称更改。我通过使用
inputSplit
来实现这一点。我在reducer中尝试了相同的方法来重命名文件,但fileSplit方法不适用于reducer。那么,有没有最好的方法将reducer的输出重命名为inputfile name呢。下面是我如何在mapper中实现它的

@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;
@覆盖
公共无效设置(上下文con)引发IOException、InterruptedException{
fileName=((FileSplit)con.getInputSplit()).getPath().getName();
fileName=fileName.substring(0,36);
outputName=新文本(文件名);
最终路径baseOutputPath=FileOutputFormat.getOutputPath(con);
最终路径outputFilePath=新路径(baseOutputPath,文件名);
TextOutputFormat write=新的TextOutputFormat(){
@凌驾
公共路径getDefaultWorkFile(TaskAttemptContext上下文,字符串扩展名)引发IOException{
返回outputFilePath;
hadoop就是这么说的:


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

我尝试过这种方法。使用这种方法,我可以编辑我的part-00000文件名,但如何获得inputfile名称作为我的reducer输出名。我已经能够获取InputSplit名称并在mapper中使用它。类似地,有没有一种方法可以读取在reducer中拆分。我能想到的一种方法是在驱动程序代码的配置中设置参数,并使用Context.getConfiguration获取值。但如果文件夹中有多个文件,此过程将不会有帮助。@Zzz您是否也能够删除r-00000扩展名。如果是,请查看我的问题。我在这里也面临同样的问题。@Zzz最后,我在作业完成后明确地修改了它。它现在对我来说工作很好,没有任何延迟,我也添加了代码来回答我的问题。谢谢
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.