2017-03-02 102 views
2

我能够正确地重命名我的减速器输出文件但r-00000仍然存在。 我在Reducer类中使用了MultipleOutputs。 这里是那个细节。不知道我错过了什么或者我还要做什么?如何删除mapreduce减速器输出r-00000延伸

public class MyReducer extends Reducer<NullWritable, Text, NullWritable, Text> { 

    private Logger logger = Logger.getLogger(MyReducer.class); 
    private MultipleOutputs<NullWritable, Text> multipleOutputs; 
    String strName = ""; 
    public void setup(Context context) { 
     logger.info("Inside Reducer."); 
     multipleOutputs = new MultipleOutputs<NullWritable, Text>(context); 
    } 
    @Override 
    public void reduce(NullWritable Key, Iterable<Text> values, Context context) 
      throws IOException, InterruptedException { 

     for (Text value : values) { 
      final String valueStr = value.toString(); 
      StringBuilder sb = new StringBuilder(); 
      sb.append(strArrvalueStr[0] + "|!|"); 
      multipleOutputs.write(NullWritable.get(), new Text(sb.toString()),strName); 
     } 
    } 

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

我觉得这个问题是重复的,请参阅以下链接: http://stackoverflow.com/questions/27488624/how-to-change-the-output-file-name-from-part-00000-in- reducer-inputfile-name –

+0

我有overriden generateFileName()方法,但无法删除r-0000扩展名。 – SUDARSHAN

回答

1

我能我的工作完成后明确地做到这一点,并在工作

if (b){ 
      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HHmm"); 
      Calendar cal = Calendar.getInstance(); 
      String strDate=dateFormat.format(cal.getTime()); 
      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")); 
        } 
       } 
      } 
     } 
+0

如何在火花输出中做同样的事情? – 2017-10-24 05:19:54

0

更合适的解决问题的方法将被改变为OUTPUTFORMAT延迟me.No这就是确定。

例如: - 如果您使用TextOutputFormatClass,只需获取TextOutputFormat类的源代码并修改以下方法以获取正确的文件名(不含r-00000)。我们需要在驱动程序中设置修改的输出格式。

public synchronized static String getUniqueFile(TaskAttemptContext context, String name, String extension) { 
    /*TaskID taskId = context.getTaskAttemptID().getTaskID(); 
    int partition = taskId.getId();*/ 
    StringBuilder result = new StringBuilder(); 
    result.append(name);   
    /* 
    * result.append('-'); 
    * result.append(TaskID.getRepresentingCharacter(taskId.getTaskType())); 
    * result.append('-'); result.append(NUMBER_FORMAT.format(partition)); 
    * result.append(extension); 
    */ 
    return result.toString(); 
} 

因此,无论通过多个输出通过哪个名称,都将根据它创建文件名。