如何从mapreduce的reducer输出中删除r-00000扩展

lztngnrs  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(331)

我能够正确地重命名我的reducer输出文件,但是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();
    }
}
dwbf0jvd

dwbf0jvd1#

我能够在我的工作完成后明确地做这件事,这对我来说没关系。工作没有延误

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"));
                    }
                }
            }
        }
yv5phkfx

yv5phkfx2#

解决这个问题的一个更合适的方法是改变输出格式。
例如:-如果您使用的是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();
}

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

相关问题