Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:07:40+00:00 2026-06-01T19:07:40+00:00

I Have managed to run the Hadoop wordcount example in a non-distributed mode; I

  • 0

I Have managed to run the Hadoop wordcount example in a non-distributed mode; I get the output in a file named “part-00000”; I can see that it lists all words of all input files combined.

After tracing the wordcount code I can see that it takes lines and splits the words based on spaces.

I am trying to think of a way to just list the words that have occurred in multiple files and their occurrences? can this be achieved in Map/Reduce?
-Added-
Are these changes appropriate?

      //changes in the parameters here

    public static class Map extends MapReduceBase implements Mapper<Text, Text, Text, Text> {

         // These are the original line; I am not using them but left them here...
      private final static IntWritable one = new IntWritable(1);
      private Text word = new Text();

                    //My changes are here too

        private Text outvalue=new Text();
        FileSplit fileSplit = (FileSplit)reporter.getInputSplit();
        private String filename = fileSplit.getPath().getName();;



      public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {

        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
        word.set(tokenizer.nextToken());

          //    And here        
              outvalue.set(filename);
          output.collect(word, outvalue);

        }

      }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:07:42+00:00Added an answer on June 1, 2026 at 7:07 pm

    You could amend the mapper to output the word as a the key, and then a Text as the value representing the filename of where the word came from. Then in your reducer, you just need to dedup the file names and output those entries where the word appears in more than a single file.

    To get the filename of the file being processed depends on whether you’re using the new API or not (mapred or mapreduce package names). I know for the new API you can extract the mapper input split from the Context object using the getInputSplit method (then probably case the InputSplit to a FileSplit, assuming you are using the TextInputFormat). For the old API, i’ve never tried it, but apparently you can use a configuration property called map.input.file

    This would also be a good choice for introducing a Combiner – to dedup out multiple word occurrences from the same mapper.

    Update

    So in response to your problem, you’re trying to use an instance variable called reporter, which doesn’t exist in the class scopt of the mapper, amend as follows:

    public static class Map extends MapReduceBase implements Mapper<Text, Text, Text, Text> {
      // These are the original line; I am not using them but left them here...
      private final static IntWritable one = new IntWritable(1);
      private Text word = new Text();
    
      //My changes are here too
      private Text outvalue=new Text();
      private String filename = null;
    
      public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
        if (filename == null) {
          filename = ((FileSplit) reporter.getInputSplit()).getPath().getName();
        }
    
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
          word.set(tokenizer.nextToken());
    
          //    And here        
          outvalue.set(filename);
          output.collect(word, outvalue);
        }
      }
    }
    

    (really not sure why SO isn’t respecting the formatting in the above…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to run hadoop examples grep, wordcount... however I am finding some
I have managed to get a cron job to run a rake task by
I'm trying to get Django's manage.py to run with modified settings files. I have
I have managed to bring the following output with this query SELECT DISTINCT IF(purchaseproduct_customerid=0,contactperson,vendorname)
I have managed to run a basic rails app1 on App Engine using: http://gist.github.com/268192
CF9, Windows Server 2008 Standard, IIS7, mySQL 5.1.48 community. I have managed to get
I just started working with PHP and have managed to run a simple CRUD
I am building a tool for out-of-container EJB testing. I have managed to run
I have managed to get code the knockoutJS jqauto auto-complete working as per the
I have an environment where there is a combination of managed and non-managed executables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.