Search in sources :

Example 1 with UnorderedKVInput

use of org.apache.tez.runtime.library.input.UnorderedKVInput in project tez by apache.

the class FilterByWordOutputProcessor method run.

@Override
public void run() throws Exception {
    if (inputs.size() != 1) {
        throw new IllegalStateException("FilterByWordOutputProcessor processor can only work with a single input");
    }
    if (outputs.size() != 1) {
        throw new IllegalStateException("FilterByWordOutputProcessor processor can only work with a single output");
    }
    for (LogicalInput input : inputs.values()) {
        input.start();
    }
    for (LogicalOutput output : outputs.values()) {
        output.start();
    }
    LogicalInput li = inputs.values().iterator().next();
    if (!(li instanceof UnorderedKVInput)) {
        throw new IllegalStateException("FilterByWordOutputProcessor processor can only work with ShuffledUnorderedKVInput");
    }
    LogicalOutput lo = outputs.values().iterator().next();
    if (!(lo instanceof MROutput)) {
        throw new IllegalStateException("FilterByWordOutputProcessor processor can only work with MROutput");
    }
    UnorderedKVInput kvInput = (UnorderedKVInput) li;
    MROutput mrOutput = (MROutput) lo;
    KeyValueReader kvReader = kvInput.getReader();
    KeyValueWriter kvWriter = mrOutput.getWriter();
    while (kvReader.next()) {
        Object key = kvReader.getCurrentKey();
        Object value = kvReader.getCurrentValue();
        kvWriter.write(key, value);
    }
}
Also used : KeyValueWriter(org.apache.tez.runtime.library.api.KeyValueWriter) LogicalOutput(org.apache.tez.runtime.api.LogicalOutput) UnorderedKVInput(org.apache.tez.runtime.library.input.UnorderedKVInput) KeyValueReader(org.apache.tez.runtime.library.api.KeyValueReader) LogicalInput(org.apache.tez.runtime.api.LogicalInput) MROutput(org.apache.tez.mapreduce.output.MROutput)

Aggregations

MROutput (org.apache.tez.mapreduce.output.MROutput)1 LogicalInput (org.apache.tez.runtime.api.LogicalInput)1 LogicalOutput (org.apache.tez.runtime.api.LogicalOutput)1 KeyValueReader (org.apache.tez.runtime.library.api.KeyValueReader)1 KeyValueWriter (org.apache.tez.runtime.library.api.KeyValueWriter)1 UnorderedKVInput (org.apache.tez.runtime.library.input.UnorderedKVInput)1