Dimitry
Dimitry

Reputation: 4593

Is the Context passed into the Mapper functions (setup,map,run,cleanup) always the same?

  1. Is the same Context passed in to setup ,map, run, cleanup within the Mapper?
  2. Will there be a case where its not the same?
  3. Can you make the context a member field within the setup?

Mapper

Upvotes: 0

Views: 290

Answers (2)

Praveen Sripati
Praveen Sripati

Reputation: 33545

Here is the documentation for Mapper.Context. Given a particular job, some of the attributes like getJobID() remains the same, while some of the attributes like getInputSplit() might be different across maps within the same job.

Upvotes: 1

Amar
Amar

Reputation: 12020

Yes inside the same mapper it is the one and same context object in setup(),map() and cleanup().

As you may see these methods are called from the run(), and that method goes like follows:

public void run(Context context) throws IOException, InterruptedException {
    setup(context);
    while (context.nextKeyValue()) {
      map(context.getCurrentKey(), context.getCurrentValue(), context);
    }
    cleanup(context);
  }

That should answer your points 1 and 2, and for point 3, you can override the run method to have more control as it's Javadoc suggests:

Expert users can override this method for more complete control over the execution of the Mapper.

And perhaps you do not need to keep a member field for context, but sure you can.

Also, while the object is same, it's properties' values mat be set or unset in any of the methods making it to be in a different state than it was when passed to another method (setup,map or cleanup).

Upvotes: 2

Related Questions