Search in sources :

Example 1 with ValuesIterator

use of org.apache.tez.runtime.library.common.ValuesIterator in project tez by apache.

the class OrderedGroupedKVInput method createValuesIterator.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected synchronized void createValuesIterator() throws IOException {
    // Not used by ReduceProcessor
    RawComparator rawComparator = ConfigUtils.getIntermediateInputKeyComparator(conf);
    Class<?> keyClass = ConfigUtils.getIntermediateInputKeyClass(conf);
    Class<?> valClass = ConfigUtils.getIntermediateInputValueClass(conf);
    LOG.info(getContext().getSourceVertexName() + ": " + "creating ValuesIterator with " + "comparator=" + rawComparator.getClass().getName() + ", keyClass=" + keyClass.getName() + ", valClass=" + valClass.getName());
    vIter = new ValuesIterator(rawIter, rawComparator, keyClass, valClass, conf, inputKeyCounter, inputValueCounter);
}
Also used : RawComparator(org.apache.hadoop.io.RawComparator) ValuesIterator(org.apache.tez.runtime.library.common.ValuesIterator)

Example 2 with ValuesIterator

use of org.apache.tez.runtime.library.common.ValuesIterator in project tez by apache.

the class OrderedGroupedKVInput method getReader.

/**
 * Get a KVReader for the Input.</p> This method will block until the input is
 * ready - i.e. the copy and merge stages are complete. Users can use the
 * isInputReady method to check if the input is ready, which gives an
 * indication of whether this method will block or not.
 *
 * NOTE: All values for the current K-V pair must be read prior to invoking
 * moveToNext. Once moveToNext() is called, the valueIterator from the
 * previous K-V pair will throw an Exception
 *
 * @return a KVReader over the sorted input.
 * @throws {@link IOInterruptedException} if IO was performing a blocking operation and was interrupted
 */
@Override
public KeyValuesReader getReader() throws IOException, TezException {
    // Cannot synchronize entire method since this is called form user code and can block.
    TezRawKeyValueIterator rawIterLocal;
    synchronized (this) {
        rawIterLocal = rawIter;
        if (getNumPhysicalInputs() == 0) {
            return new KeyValuesReader() {

                @Override
                public boolean next() throws IOException {
                    getContext().notifyProgress();
                    hasCompletedProcessing();
                    completedProcessing = true;
                    return false;
                }

                @Override
                public Object getCurrentKey() throws IOException {
                    throw new RuntimeException("No data available in Input");
                }

                @Override
                public Iterable<Object> getCurrentValues() throws IOException {
                    throw new RuntimeException("No data available in Input");
                }
            };
        }
    }
    if (rawIterLocal == null) {
        try {
            waitForInputReady();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOInterruptedException("Interrupted while waiting for input ready", e);
        }
    }
    @SuppressWarnings("rawtypes") ValuesIterator valuesIter = null;
    synchronized (this) {
        valuesIter = vIter;
    }
    return new OrderedGroupedKeyValuesReader(valuesIter, getContext());
}
Also used : IOInterruptedException(org.apache.tez.runtime.library.api.IOInterruptedException) KeyValuesReader(org.apache.tez.runtime.library.api.KeyValuesReader) ValuesIterator(org.apache.tez.runtime.library.common.ValuesIterator) IOInterruptedException(org.apache.tez.runtime.library.api.IOInterruptedException) TezRawKeyValueIterator(org.apache.tez.runtime.library.common.sort.impl.TezRawKeyValueIterator)

Aggregations

ValuesIterator (org.apache.tez.runtime.library.common.ValuesIterator)2 RawComparator (org.apache.hadoop.io.RawComparator)1 IOInterruptedException (org.apache.tez.runtime.library.api.IOInterruptedException)1 KeyValuesReader (org.apache.tez.runtime.library.api.KeyValuesReader)1 TezRawKeyValueIterator (org.apache.tez.runtime.library.common.sort.impl.TezRawKeyValueIterator)1