Search in sources :

Example 1 with NullKeyFieldException

use of org.apache.flink.types.NullKeyFieldException 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
            code *= HASH_SALT[i & 0x1F];
            // component
            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 2 with NullKeyFieldException

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

the class TupleComparator method compare.

@SuppressWarnings("unchecked")
@Override
public int compare(T first, T second) {
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            int keyPos = keyPositions[i];
            int cmp = comparators[i].compare(first.getFieldNotNull(keyPos), second.getFieldNotNull(keyPos));
            if (cmp != 0) {
                return cmp;
            }
        }
        return 0;
    } 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 NullKeyFieldException

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

the class TupleComparator method putNormalizedKey.

@SuppressWarnings("unchecked")
@Override
public void putNormalizedKey(T value, 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;
            this.comparators[i].putNormalizedKey(value.getFieldNotNull(this.keyPositions[i]), target, offset, len);
            numBytes -= len;
            offset += len;
        }
    } catch (NullFieldException nfex) {
        throw new NullKeyFieldException(nfex);
    } catch (NullPointerException npex) {
        throw new NullKeyFieldException(this.keyPositions[i]);
    }
}
Also used : NullKeyFieldException(org.apache.flink.types.NullKeyFieldException) NullFieldException(org.apache.flink.types.NullFieldException)

Example 4 with NullKeyFieldException

use of org.apache.flink.types.NullKeyFieldException 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 5 with NullKeyFieldException

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

the class RecordComparator method compare.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compare(Record first, Record second) {
    int i = 0;
    try {
        for (; i < this.keyFields.length; i++) {
            Comparable k1 = (Comparable) first.getField(this.keyFields[i], this.keyHolders[i]);
            Comparable k2 = (Comparable) second.getField(this.keyFields[i], this.transientKeyHolders[i]);
            int cmp = k1.compareTo(k2);
            if (cmp != 0) {
                return cmp;
            }
        }
        return 0;
    } catch (NullPointerException e) {
        throw new NullKeyFieldException(this.keyFields[i]);
    }
}
Also used : NullKeyFieldException(org.apache.flink.types.NullKeyFieldException)

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