Example usage for org.apache.hadoop.mapreduce TaskAttemptContext getMapperClass

List of usage examples for org.apache.hadoop.mapreduce TaskAttemptContext getMapperClass

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce TaskAttemptContext getMapperClass.

Prototype

public Class<? extends Mapper<?, ?, ?, ?>> getMapperClass() throws ClassNotFoundException;

Source Link

Document

Get the Mapper class for the job.

Usage

From source file:org.apache.tez.mapreduce.processor.map.MapProcessor.java

License:Apache License

private void runNewMapper(final JobConf job, MRTaskReporter reporter, final MRInputLegacy in,
        KeyValueWriter out) throws IOException, InterruptedException {

    // Initialize input in-line since it sets parameters which may be used by the processor.
    // Done only for MRInput.
    // TODO use new method in MRInput to get required info
    //in.initialize(job, master);

    // make a task context so we can get the classes
    org.apache.hadoop.mapreduce.TaskAttemptContext taskContext = getTaskAttemptContext();

    // make a mapper
    org.apache.hadoop.mapreduce.Mapper mapper;
    try {/* w w w  . java  2  s  . c  om*/
        mapper = (org.apache.hadoop.mapreduce.Mapper) ReflectionUtils.newInstance(taskContext.getMapperClass(),
                job);
    } catch (ClassNotFoundException cnfe) {
        throw new IOException(cnfe);
    }

    org.apache.hadoop.mapreduce.RecordReader input = new NewRecordReader(in);

    org.apache.hadoop.mapreduce.RecordWriter output = new NewOutputCollector(out);

    org.apache.hadoop.mapreduce.InputSplit split = in.getNewInputSplit();

    updateJobWithSplit(job, split);

    org.apache.hadoop.mapreduce.MapContext mapContext = new MapContextImpl(job, taskAttemptId, input, output,
            committer, processorContext, split, reporter);

    org.apache.hadoop.mapreduce.Mapper.Context mapperContext = new WrappedMapper().getMapContext(mapContext);

    input.initialize(split, mapperContext);
    mapper.run(mapperContext);
    // Set progress to 1.0f if there was no exception,
    reporter.setProgress(1.0f);

    this.statusUpdate();
    input.close();
    output.close(mapperContext);
}