2017-03-02 103 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(); 
} 

因此,無論通過多個輸出通過哪個名稱,都將根據它創建文件名。