Search in sources :

Example 6 with KeyValueWriter

use of org.apache.tez.runtime.library.api.KeyValueWriter in project tez by apache.

the class MapProcessor method run.

@Override
public void run(Map<String, LogicalInput> _inputs, Map<String, LogicalOutput> _outputs) throws Exception {
    this.inputs = _inputs;
    this.outputs = _outputs;
    progressHelper = new ProgressHelper(this.inputs, getContext(), this.getClass().getSimpleName());
    LOG.info("Running map: " + processorContext.getUniqueIdentifier());
    if (_inputs.size() != 1 || _outputs.size() != 1) {
        throw new IOException("Cannot handle multiple _inputs or _outputs" + ", inputCount=" + _inputs.size() + ", outputCount=" + _outputs.size());
    }
    for (LogicalInput input : _inputs.values()) {
        input.start();
    }
    for (LogicalOutput output : _outputs.values()) {
        output.start();
    }
    LogicalInput in = _inputs.values().iterator().next();
    LogicalOutput out = _outputs.values().iterator().next();
    initTask(out);
    progressHelper.scheduleProgressTaskService(0, 100);
    // Sanity check
    if (!(in instanceof MRInputLegacy)) {
        throw new IOException(new TezException("Only MRInputLegacy supported. Input: " + in.getClass()));
    }
    MRInputLegacy input = (MRInputLegacy) in;
    input.init();
    Configuration incrementalConf = input.getConfigUpdates();
    if (incrementalConf != null) {
        for (Entry<String, String> entry : incrementalConf) {
            jobConf.set(entry.getKey(), entry.getValue());
        }
    }
    KeyValueWriter kvWriter = null;
    if ((out instanceof MROutputLegacy)) {
        kvWriter = ((MROutputLegacy) out).getWriter();
    } else if ((out instanceof OrderedPartitionedKVOutput)) {
        kvWriter = ((OrderedPartitionedKVOutput) out).getWriter();
    } else {
        throw new IOException("Illegal output to map, outputClass=" + out.getClass());
    }
    if (useNewApi) {
        runNewMapper(jobConf, mrReporter, input, kvWriter);
    } else {
        runOldMapper(jobConf, mrReporter, input, kvWriter);
    }
    done();
}
Also used : TezException(org.apache.tez.dag.api.TezException) KeyValueWriter(org.apache.tez.runtime.library.api.KeyValueWriter) ProgressHelper(org.apache.tez.common.ProgressHelper) Configuration(org.apache.hadoop.conf.Configuration) LogicalOutput(org.apache.tez.runtime.api.LogicalOutput) MROutputLegacy(org.apache.tez.mapreduce.output.MROutputLegacy) LogicalInput(org.apache.tez.runtime.api.LogicalInput) OrderedPartitionedKVOutput(org.apache.tez.runtime.library.output.OrderedPartitionedKVOutput) IOException(java.io.IOException) MRInputLegacy(org.apache.tez.mapreduce.input.MRInputLegacy)

Example 7 with KeyValueWriter

use of org.apache.tez.runtime.library.api.KeyValueWriter in project tez by apache.

the class MROutput method getWriter.

/**
 * Get a key value write to write Map Reduce compatible output
 */
@Override
public KeyValueWriter getWriter() throws IOException {
    return new KeyValueWriter() {

        private final boolean useNewWriter = useNewApi;

        @SuppressWarnings("unchecked")
        @Override
        public void write(Object key, Object value) throws IOException {
            if (useNewWriter) {
                try {
                    newRecordWriter.write(key, value);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new IOInterruptedException("Interrupted while writing next key-value", e);
                }
            } else {
                oldRecordWriter.write(key, value);
            }
            outputRecordCounter.increment(1);
            getContext().notifyProgress();
        }
    };
}
Also used : KeyValueWriter(org.apache.tez.runtime.library.api.KeyValueWriter) IOInterruptedException(org.apache.tez.runtime.library.api.IOInterruptedException) IOInterruptedException(org.apache.tez.runtime.library.api.IOInterruptedException)

Aggregations

KeyValueWriter (org.apache.tez.runtime.library.api.KeyValueWriter)7 Configuration (org.apache.hadoop.conf.Configuration)4 LogicalInput (org.apache.tez.runtime.api.LogicalInput)4 LogicalOutput (org.apache.tez.runtime.api.LogicalOutput)4 Text (org.apache.hadoop.io.Text)3 ProgressHelper (org.apache.tez.common.ProgressHelper)3 IOException (java.io.IOException)2 IntWritable (org.apache.hadoop.io.IntWritable)2 TezSharedExecutor (org.apache.tez.common.TezSharedExecutor)2 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)2 MRInputLegacy (org.apache.tez.mapreduce.input.MRInputLegacy)2 MROutputLegacy (org.apache.tez.mapreduce.output.MROutputLegacy)2 Event (org.apache.tez.runtime.api.Event)2 OutputContext (org.apache.tez.runtime.api.OutputContext)2 CompositeDataMovementEvent (org.apache.tez.runtime.api.events.CompositeDataMovementEvent)2 KeyValueReader (org.apache.tez.runtime.library.api.KeyValueReader)2 TezRuntimeConfiguration (org.apache.tez.runtime.library.api.TezRuntimeConfiguration)2 OrderedPartitionedKVOutput (org.apache.tez.runtime.library.output.OrderedPartitionedKVOutput)2 DataMovementEventPayloadProto (org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.DataMovementEventPayloadProto)2 Test (org.junit.Test)2