Input file name in the mapper in a Hadoop program

0 votes
I want the name of the input file within a mapper. There are multiple input files stored in the input directory, each mapper may read a different file, and I need to know which file the mapper has read.
Jul 23 in Linux Administration by Upasana
• 8,530 points
48 views

1 answer to this question.

0 votes

Try this inside your mapper :

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

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

String fileName = new String();
public void configure(JobConf job)
{
   filename = job.get("map.input.file");
}
answered Jul 23 by Shubham
• 13,290 points

Related Questions In Linux Administration

0 votes
1 answer
0 votes
1 answer

how to loop through the content of a file using bash

One of the ways to do it ...READ MORE

answered Feb 15 in Linux Administration by ajs3033
• 7,280 points
73 views
0 votes
1 answer

Counting lines in a file/doc.

you can do this by using word ...READ MORE

answered Mar 5 in Linux Administration by DareDev
• 6,810 points
27 views
0 votes
1 answer
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,670 points
2,760 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,670 points
290 views
0 votes
10 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
13,658 views
0 votes
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,240 points
1,002 views
0 votes
1 answer

Script file name in a Bash script

$0 will give you the complete basename. ...READ MORE

answered Jun 20 in Linux Administration by Shubham
• 13,290 points
19 views
0 votes
1 answer

Writing a heredoc to a file in a script

try to use tee: tee newfile <<EOF line 1 line 2 line ...READ MORE

answered May 20 in Linux Administration by Shubham
• 13,290 points
46 views