Search in sources :

Example 1 with KeyFieldOutOfBoundsException

use of org.apache.flink.types.KeyFieldOutOfBoundsException in project flink by apache.

the class OutputEmitterTest method testMissingKey.

@Test
public void testMissingKey() {
    // Test for IntValue
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> intComp = new RecordComparatorFactory(new int[] { 1 }, new Class[] { IntValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.PARTITION_HASH, intComp);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
    Record rec = new Record(0);
    rec.setField(0, new IntValue(1));
    delegate.setInstance(rec);
    try {
        oe1.selectChannels(delegate, 100);
    } catch (KeyFieldOutOfBoundsException re) {
        Assert.assertEquals(1, re.getFieldNumber());
        return;
    }
    Assert.fail("Expected a KeyFieldOutOfBoundsException.");
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) Record(org.apache.flink.types.Record) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 2 with KeyFieldOutOfBoundsException

use of org.apache.flink.types.KeyFieldOutOfBoundsException in project flink by apache.

the class TupleComparator method hash.

// --------------------------------------------------------------------------------------------
//  Comparator Methods
// --------------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public int hash(T value) {
    int i = 0;
    try {
        int code = this.comparators[0].hash(value.getFieldNotNull(keyPositions[0]));
        for (i = 1; i < this.keyPositions.length; i++) {
            // salt code with (i % HASH_SALT.length)-th salt component
            code *= HASH_SALT[i & 0x1F];
            code += this.comparators[i].hash(value.getFieldNotNull(keyPositions[i]));
        }
        return code;
    } catch (NullFieldException nfex) {
        throw new NullKeyFieldException(nfex);
    } catch (IndexOutOfBoundsException iobex) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException) NullFieldException(org.apache.flink.types.NullFieldException)

Example 3 with KeyFieldOutOfBoundsException

use of org.apache.flink.types.KeyFieldOutOfBoundsException in project flink by apache.

the class TupleComparatorBase method compareSerialized.

@SuppressWarnings("unchecked")
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
    if (deserializedFields1 == null) {
        instantiateDeserializationUtils();
    }
    int i = 0;
    try {
        for (; i < serializers.length; i++) {
            deserializedFields1[i] = serializers[i].deserialize(deserializedFields1[i], firstSource);
            deserializedFields2[i] = serializers[i].deserialize(deserializedFields2[i], secondSource);
        }
        for (i = 0; i < keyPositions.length; i++) {
            int keyPos = keyPositions[i];
            int cmp = comparators[i].compare(deserializedFields1[keyPos], deserializedFields2[keyPos]);
            if (cmp != 0) {
                return cmp;
            }
        }
        return 0;
    } catch (NullPointerException npex) {
        throw new NullKeyFieldException(keyPositions[i]);
    } catch (IndexOutOfBoundsException iobex) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i], iobex);
    }
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException)

Example 4 with KeyFieldOutOfBoundsException

use of org.apache.flink.types.KeyFieldOutOfBoundsException in project flink by apache.

the class RowComparator method compare.

@Override
public int compare(Row first, Row second) {
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            int keyPos = keyPositions[i];
            TypeComparator<Object> comparator = comparators[i];
            // element can be null
            Object firstElement = first.getField(keyPos);
            // element can be null
            Object secondElement = second.getField(keyPos);
            int cmp = comparator.compare(firstElement, secondElement);
            if (cmp != 0) {
                return cmp;
            }
        }
    } catch (IndexOutOfBoundsException e) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
    return 0;
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException)

Example 5 with KeyFieldOutOfBoundsException

use of org.apache.flink.types.KeyFieldOutOfBoundsException in project flink by apache.

the class RowComparator method setReference.

@Override
public void setReference(Row toCompare) {
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            TypeComparator<Object> comparator = comparators[i];
            Object element = toCompare.getField(keyPositions[i]);
            // element can be null
            comparator.setReference(element);
        }
    } catch (IndexOutOfBoundsException e) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException)

Aggregations

KeyFieldOutOfBoundsException (org.apache.flink.types.KeyFieldOutOfBoundsException)11 NullKeyFieldException (org.apache.flink.types.NullKeyFieldException)5 NullFieldException (org.apache.flink.types.NullFieldException)2 OutputEmitter (org.apache.flink.runtime.operators.shipping.OutputEmitter)1 SerializationDelegate (org.apache.flink.runtime.plugable.SerializationDelegate)1 RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)1 RecordSerializerFactory (org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory)1 IntValue (org.apache.flink.types.IntValue)1 Record (org.apache.flink.types.Record)1 Test (org.junit.Test)1