How to get the input file name in the mapper in a Hadoop program?

后端 未结 10 2026
粉色の甜心
粉色の甜心 2020-11-29 18:48

How I can get the name of the input file within a mapper? I have multiple input files stored in the input directory, each mapper may read a different file, and I need to kno

10条回答
  •  遥遥无期
    2020-11-29 19:19

    For org.apache.hadood.mapred package the map function signature should be:

    map(Object, Object, OutputCollector, Reporter) 
    

    So, to get the file name inside the map function, you could use the Reporter object like this:

    String fileName = ((FileSplit) reporter.getInputSplit()).getPath().getName();
    

提交回复
热议问题