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