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

后端 未结 10 2024
粉色の甜心
粉色の甜心 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:24

    Use this inside your mapper :

    FileSplit fileSplit = (FileSplit)context.getInputSplit();
    String filename = fileSplit.getPath().getName();
    

    Edit :

    Try this if you want to do it inside configure() through the old API :

    String fileName = new String();
    public void configure(JobConf job)
    {
       filename = job.get("map.input.file");
    }
    

提交回复
热议问题