Example usage for org.apache.hadoop.mapred JobConf getMapperClass

List of usage examples for org.apache.hadoop.mapred JobConf getMapperClass

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred JobConf getMapperClass.

Prototype

public Class<? extends Mapper> getMapperClass() 

Source Link

Document

Get the Mapper class for the job.

Usage

From source file:org.archive.mapred.ARCMapRunner.java

License:LGPL

public void configure(JobConf job) {
    this.mapper = (ARCRecordMapper) ReflectionUtils.newInstance(job.getMapperClass(), job);
    // Value is in minutes.
    this.maxtime = job.getLong("wax.index.timeout", 60) * 60 * 1000;
}

From source file:org.gridgain.grid.kernal.processors.hadoop.v1.GridHadoopV1MapTask.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*from w  ww  . j  a v  a 2s.c  o m*/
public void run(GridHadoopTaskContext taskCtx) throws GridException {
    GridHadoopJob job = taskCtx.job();

    GridHadoopV2TaskContext ctx = (GridHadoopV2TaskContext) taskCtx;

    JobConf jobConf = ctx.jobConf();

    InputFormat inFormat = jobConf.getInputFormat();

    GridHadoopInputSplit split = info().inputSplit();

    InputSplit nativeSplit;

    if (split instanceof GridHadoopFileBlock) {
        GridHadoopFileBlock block = (GridHadoopFileBlock) split;

        nativeSplit = new FileSplit(new Path(block.file().toString()), block.start(), block.length(),
                EMPTY_HOSTS);
    } else
        nativeSplit = (InputSplit) ctx.getNativeSplit(split);

    assert nativeSplit != null;

    Reporter reporter = new GridHadoopV1Reporter(taskCtx);

    GridHadoopV1OutputCollector collector = null;

    try {
        collector = collector(jobConf, ctx, !job.info().hasCombiner() && !job.info().hasReducer(), fileName(),
                ctx.attemptId());

        RecordReader reader = inFormat.getRecordReader(nativeSplit, jobConf, reporter);

        Mapper mapper = ReflectionUtils.newInstance(jobConf.getMapperClass(), jobConf);

        Object key = reader.createKey();
        Object val = reader.createValue();

        assert mapper != null;

        try {
            try {
                while (reader.next(key, val)) {
                    if (isCancelled())
                        throw new GridHadoopTaskCancelledException("Map task cancelled.");

                    mapper.map(key, val, collector, reporter);
                }
            } finally {
                mapper.close();
            }
        } finally {
            collector.closeWriter();
        }

        collector.commit();
    } catch (Exception e) {
        if (collector != null)
            collector.abort();

        throw new GridException(e);
    }
}