Search in sources :

Example 6 with NullKeyFieldException

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

the class RecordComparator method putNormalizedKey.

@Override
public void putNormalizedKey(Record record, MemorySegment target, int offset, int numBytes) {
    int i = 0;
    try {
        for (; i < this.numLeadingNormalizableKeys & numBytes > 0; i++) {
            int len = this.normalizedKeyLengths[i];
            len = numBytes >= len ? len : numBytes;
            ((NormalizableKey<?>) record.getField(this.keyFields[i], this.transientKeyHolders[i])).copyNormalizedKey(target, offset, len);
            numBytes -= len;
            offset += len;
        }
    } catch (NullPointerException npex) {
        throw new NullKeyFieldException(this.keyFields[i]);
    }
}
Also used : NormalizableKey(org.apache.flink.types.NormalizableKey) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException)

Example 7 with NullKeyFieldException

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

the class OutputEmitterTest method testNullKey.

@Test
public void testNullKey() {
    // Test for IntValue
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> intComp = new RecordComparatorFactory(new int[] { 0 }, 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(2);
    rec.setField(1, new IntValue(1));
    delegate.setInstance(rec);
    try {
        oe1.selectChannels(delegate, 100);
    } catch (NullKeyFieldException re) {
        Assert.assertEquals(0, re.getFieldNumber());
        return;
    }
    Assert.fail("Expected a NullKeyFieldException.");
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException) 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 8 with NullKeyFieldException

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

the class PojoComparator method compareToReference.

@Override
public int compareToReference(TypeComparator<T> referencedComparator) {
    PojoComparator<T> other = (PojoComparator<T>) referencedComparator;
    int i = 0;
    try {
        for (; i < this.keyFields.length; i++) {
            int cmp = this.comparators[i].compareToReference(other.comparators[i]);
            if (cmp != 0) {
                return cmp;
            }
        }
        return 0;
    } catch (NullPointerException npex) {
        throw new NullKeyFieldException(this.keyFields[i].toString());
    }
}
Also used : NullKeyFieldException(org.apache.flink.types.NullKeyFieldException)

Example 9 with NullKeyFieldException

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

the class TupleComparatorBase method compareToReference.

// --------------------------------------------------------------------------------------------
// Comparator Methods
// --------------------------------------------------------------------------------------------
@Override
public int compareToReference(TypeComparator<T> referencedComparator) {
    TupleComparatorBase<T> other = (TupleComparatorBase<T>) referencedComparator;
    int i = 0;
    try {
        for (; i < this.keyPositions.length; i++) {
            @SuppressWarnings("unchecked") int cmp = this.comparators[i].compareToReference(other.comparators[i]);
            if (cmp != 0) {
                return cmp;
            }
        }
        return 0;
    } catch (NullPointerException npex) {
        throw new NullKeyFieldException(keyPositions[i]);
    } catch (IndexOutOfBoundsException iobex) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException)

Example 10 with NullKeyFieldException

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

the class OutputEmitterTest method verifyWrongPartitionHashKey.

private boolean verifyWrongPartitionHashKey(int position, int fieldNum) {
    final TypeComparator<Record> comparator = new RecordComparatorFactory(new int[] { position }, new Class[] { IntValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(ShipStrategyType.PARTITION_HASH, comparator, 100);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());
    Record record = new Record(2);
    record.setField(fieldNum, new IntValue(1));
    delegate.setInstance(record);
    try {
        selector.selectChannel(delegate);
    } catch (NullKeyFieldException re) {
        Assert.assertEquals(position, re.getFieldNumber());
        return true;
    }
    return false;
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException) 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)

Aggregations

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