Search in sources :

Example 6 with KeyFieldOutOfBoundsException

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

the class RowComparator method hash.

@Override
public int hash(Row record) {
    int code = 0;
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            code *= TupleComparatorBase.HASH_SALT[i & 0x1F];
            // element can be null
            Object element = record.getField(keyPositions[i]);
            code += comparators[i].hash(element);
        }
    } catch (IndexOutOfBoundsException e) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
    return code;
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException)

Example 7 with KeyFieldOutOfBoundsException

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

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

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

the class RowComparator method compareToReference.

@Override
public int compareToReference(TypeComparator<Row> referencedComparator) {
    RowComparator other = (RowComparator) referencedComparator;
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            int cmp = comparators[i].compareToReference(other.comparators[i]);
            if (cmp != 0) {
                return cmp;
            }
        }
    } catch (IndexOutOfBoundsException e) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
    return 0;
}
Also used : KeyFieldOutOfBoundsException(org.apache.flink.types.KeyFieldOutOfBoundsException)

Example 10 with KeyFieldOutOfBoundsException

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

the class RowComparator method equalToReference.

@Override
public boolean equalToReference(Row candidate) {
    int i = 0;
    try {
        for (; i < keyPositions.length; i++) {
            TypeComparator<Object> comparator = comparators[i];
            // element can be null
            Object element = candidate.getField(keyPositions[i]);
            // check if reference is not equal
            if (!comparator.equalToReference(element)) {
                return false;
            }
        }
    } catch (IndexOutOfBoundsException e) {
        throw new KeyFieldOutOfBoundsException(keyPositions[i]);
    }
    return true;
}
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