복붙노트

[HADOOP] mapreduce의 감속기 출력에서 ​​r-00000 확장을 제거하는 방법

HADOOP

mapreduce의 감속기 출력에서 ​​r-00000 확장을 제거하는 방법

감속기 출력 파일의 이름을 올바르게 바꿀 수 있지만 r-00000은 계속 유지됩니다. 감속기 클래스에서 MultipleOutputs를 사용했습니다. 여기에 자세한 내용이 있습니다. 내가 무엇을 누락했는지 또는 내가해야 할 추가 사항이 확실하지 않습니까?

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();
    }
}

해결법

  1. ==============================

    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"));
                        }
                    }
                }
            }
    
  2. ==============================

    2.문제에 대한 더 적합한 방법은 OutputFormat을 변경하는 것입니다.

    문제에 대한 더 적합한 방법은 OutputFormat을 변경하는 것입니다.

    예를 들면 :-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();
    }
    

    따라서 여러 출력에 이름이 전달되면 파일 이름이 그에 따라 생성됩니다.

  3. from https://stackoverflow.com/questions/42547065/how-to-remove-r-00000-extention-from-reducer-output-in-mapreduce by cc-by-sa and MIT license