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.");
}
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]);
}
}
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);
}
}
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;
}
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]);
}
}
Aggregations