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, 2019 in Linux Administration by Upasana
• 8,570 points
234 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, 2019 by Shubham
• 13,370 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, 2019 in Linux Administration by ajs3033
• 7,280 points
135 views
0 votes
1 answer

Counting lines in a file/doc.

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

answered Mar 5, 2019 in Linux Administration by DareDev
• 6,850 points
39 views
0 votes
1 answer

How to extract file base name without path and extension in bash?

You don't actually have to call the ...READ MORE

answered May 31, 2019 in Linux Administration by Shubham
• 13,370 points
262 views
+1 vote
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,840 points
3,933 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,840 points
544 views
+1 vote
11 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
20,969 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,290 points
1,484 views
0 votes
1 answer

Script file name in a Bash script

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

answered Jun 20, 2019 in Linux Administration by Shubham
• 13,370 points
42 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, 2019 in Linux Administration by Shubham
• 13,370 points
88 views