Search in sources :

Example 11 with KeyValuesReader

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

the class TestSortedGroupedMergedInput method testOrdering.

@Test(timeout = 5000)
public void testOrdering() throws Exception {
    SortedTestKeyValuesReader kvsReader1 = new SortedTestKeyValuesReader(new int[] { 2, 4 }, new int[][] { { 2, 2 }, { 4, 4 } });
    SortedTestKeyValuesReader kvsReader2 = new SortedTestKeyValuesReader(new int[] { 1, 2, 3 }, new int[][] { { 1, 1 }, { 2, 2 }, { 3, 3 } });
    SortedTestKeyValuesReader kvsReader3 = new SortedTestKeyValuesReader(new int[] { 4, 5, 6, 7 }, new int[][] { { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 } });
    SortedTestInput sInput1 = new SortedTestInput(kvsReader1);
    SortedTestInput sInput2 = new SortedTestInput(kvsReader2);
    SortedTestInput sInput3 = new SortedTestInput(kvsReader3);
    List<Input> sInputs = new LinkedList<Input>();
    sInputs.add(sInput1);
    sInputs.add(sInput2);
    sInputs.add(sInput3);
    OrderedGroupedMergedKVInput input = new OrderedGroupedMergedKVInput(createMergedInputContext(), sInputs);
    KeyValuesReader kvsReader = input.getReader();
    int keyCount = 0;
    while (kvsReader.next()) {
        keyCount++;
        Integer key = (Integer) kvsReader.getCurrentKey();
        assertEquals(Integer.valueOf(keyCount), key);
        Iterator<Object> valuesIter = kvsReader.getCurrentValues().iterator();
        int valCount = 0;
        while (valuesIter.hasNext()) {
            valCount++;
            Integer val = (Integer) valuesIter.next();
            assertEquals(Integer.valueOf(keyCount), val);
        }
        if (keyCount == 1) {
            assertEquals(2, valCount);
        } else if (keyCount == 2) {
            assertEquals(4, valCount);
        } else if (keyCount == 3) {
            assertEquals(2, valCount);
        } else if (keyCount == 4) {
            assertEquals(4, valCount);
        } else if (keyCount == 5 || keyCount == 6 || keyCount == 7) {
            assertEquals(2, valCount);
        } else {
            fail("Unexpected key");
        }
    }
    getNextFromFinishedReader(kvsReader);
}
Also used : Input(org.apache.tez.runtime.api.Input) KeyValuesReader(org.apache.tez.runtime.library.api.KeyValuesReader) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 12 with KeyValuesReader

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

the class TestSortedGroupedMergedInput method testEmptySources.

@Test(timeout = 5000)
public void testEmptySources() throws Exception {
    SortedTestKeyValuesReader kvsReader1 = new SortedTestKeyValuesReader(new int[] {}, new int[][] {});
    SortedTestKeyValuesReader kvsReader2 = new SortedTestKeyValuesReader(new int[] {}, new int[][] {});
    SortedTestKeyValuesReader kvsReader3 = new SortedTestKeyValuesReader(new int[] {}, new int[][] {});
    SortedTestInput sInput1 = new SortedTestInput(kvsReader1);
    SortedTestInput sInput2 = new SortedTestInput(kvsReader2);
    SortedTestInput sInput3 = new SortedTestInput(kvsReader3);
    List<Input> sInputs = new LinkedList<Input>();
    sInputs.add(sInput1);
    sInputs.add(sInput2);
    sInputs.add(sInput3);
    OrderedGroupedMergedKVInput input = new OrderedGroupedMergedKVInput(createMergedInputContext(), sInputs);
    KeyValuesReader kvsReader = input.getReader();
    assertTrue(kvsReader.next() == false);
    getNextFromFinishedReader(kvsReader);
}
Also used : Input(org.apache.tez.runtime.api.Input) KeyValuesReader(org.apache.tez.runtime.library.api.KeyValuesReader) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with KeyValuesReader

use of org.apache.tez.runtime.library.api.KeyValuesReader 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

KeyValuesReader (org.apache.tez.runtime.library.api.KeyValuesReader)13 LinkedList (java.util.LinkedList)9 Input (org.apache.tez.runtime.api.Input)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)2 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)2 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)2 BinarySortableSerDe (org.apache.hadoop.hive.serde2.binarysortable.BinarySortableSerDe)2 BinarySortableDeserializeRead (org.apache.hadoop.hive.serde2.binarysortable.fast.BinarySortableDeserializeRead)2 LazyBinaryDeserializeRead (org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinaryDeserializeRead)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)2 MergedInputContext (org.apache.tez.runtime.api.MergedInputContext)2 KeyValueReader (org.apache.tez.runtime.library.api.KeyValueReader)2 IOException (java.io.IOException)1 VectorExpressionWriter (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter)1 RawComparator (org.apache.hadoop.io.RawComparator)1 ProgressHelper (org.apache.tez.common.ProgressHelper)1 MROutputLegacy (org.apache.tez.mapreduce.output.MROutputLegacy)1 LogicalInput (org.apache.tez.runtime.api.LogicalInput)1