得到mapper task所处理的文件的文件名

有时候,当我们在使用hadoop处理数据时,我们想知道mapper所处理的这个file chunk(文件块)在hdfs中的文件名是什么。将下面的代码加入你的mapper中,可以得到当前mapper所处理输入文件的文件名:

1 FileSplit fileSplit = (FileSplit)context.getInputSplit();
2 String filename = fileSplit.getPath().getName();
3 System.out.println("File name "+filename);
4 System.out.println("Directory and File name"+fileSplit.getPath().toString());

标准输出在hadoop/logs/...../userlogs/....大概就是这个文件夹里面,自己去查看文件,就可以看到输出的内容了。

参考:

https://sites.google.com/site/hadoopandhive/home/how-to-get-the-name-of-the-file-being-executed-by-the-mapper-in-hadoop-map-reduce-framework

原文地址:https://www.cnblogs.com/hengli/p/2812736.html