org.apache.flink.types.NullKeyFieldException Java Examples

The following examples show how to use org.apache.flink.types.NullKeyFieldException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PojoComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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());
	}
}
 
Example #2
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #3
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compareSerialized(DataInputView source1, DataInputView source2) throws IOException {
	this.temp1.read(source1);
	this.temp2.read(source2);
	
	for (int i = 0; i < this.keyFields.length; i++) {
		@SuppressWarnings("rawtypes")
		final Comparable k1 = (Comparable) this.temp1.getField(this.keyFields[i], this.keyHolders[i]);
		@SuppressWarnings("rawtypes")
		final Comparable k2 = (Comparable) this.temp2.getField(this.keyFields[i], this.transientKeyHolders[i]);
		
		if (k1 == null || k2 == null) {
			throw new NullKeyFieldException(this.keyFields[i]);
		}
		
		@SuppressWarnings("unchecked")
		final int comp = k1.compareTo(k2);
		if (comp != 0) {
			return this.ascending[i] ? comp : -comp;
		}
	}
	return 0;
}
 
Example #4
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int hash(Record object) {
	int i = 0;
	try {
		int code = 0;
		for (; i < this.keyFields.length; i++) {
			code ^= object.getField(this.keyFields[i], this.transientKeyHolders[i]).hashCode();
			code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component
		}
		return code;
	}
	catch (NullPointerException npex) {
		throw new NullKeyFieldException(this.keyFields[i]);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(this.keyFields[i]);
	}
}
 
Example #5
Source File: PojoComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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());
	}
}
 
Example #6
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: TupleComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #8
Source File: RecordComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int compareSerialized(DataInputView source1, DataInputView source2) throws IOException {
	this.temp1.read(source1);
	this.temp2.read(source2);
	
	for (int i = 0; i < this.keyFields.length; i++) {
		@SuppressWarnings("rawtypes")
		final Comparable k1 = (Comparable) this.temp1.getField(this.keyFields[i], this.keyHolders[i]);
		@SuppressWarnings("rawtypes")
		final Comparable k2 = (Comparable) this.temp2.getField(this.keyFields[i], this.transientKeyHolders[i]);
		
		if (k1 == null || k2 == null) {
			throw new NullKeyFieldException(this.keyFields[i]);
		}
		
		@SuppressWarnings("unchecked")
		final int comp = k1.compareTo(k2);
		if (comp != 0) {
			return this.ascending[i] ? comp : -comp;
		}
	}
	return 0;
}
 
Example #9
Source File: RecordComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #10
Source File: TupleComparatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #11
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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++) {
			code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt 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]);
	}
}
 
Example #12
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setReference(T toCompare) {
	int i = 0;
	try {
		for (; i < this.keyPositions.length; i++) {
			this.comparators[i].setReference(toCompare.getFieldNotNull(this.keyPositions[i]));
		}
	}
	catch (NullFieldException nfex) {
		throw new NullKeyFieldException(nfex);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(keyPositions[i]);
	}
}
 
Example #13
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean equalToReference(T candidate) {
	int i = 0;
	try {
		for (; i < this.keyPositions.length; i++) {
			if (!this.comparators[i].equalToReference(candidate.getFieldNotNull(this.keyPositions[i]))) {
				return false;
			}
		}
		return true;
	}
	catch (NullFieldException nfex) {
		throw new NullKeyFieldException(nfex);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(keyPositions[i]);
	}
}
 
Example #14
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #15
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #16
Source File: RecordPairComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compareToReference(Record candidate) {
	for (int i = 0; i < this.keyFields2.length; i++) {
		final Comparable k = (Comparable) candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
		if (k == null) {
			throw new NullKeyFieldException(this.keyFields2[i]);
		} else {
			final int comp = k.compareTo(this.keyHolders1[i]);
			if (comp != 0) {
				return comp;
			}
		}
	}
	return 0;
}
 
Example #17
Source File: PojoComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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());
	}
}
 
Example #18
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #19
Source File: TupleComparatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #20
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #21
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean equalToReference(T candidate) {
	int i = 0;
	try {
		for (; i < this.keyPositions.length; i++) {
			if (!this.comparators[i].equalToReference(candidate.getFieldNotNull(this.keyPositions[i]))) {
				return false;
			}
		}
		return true;
	}
	catch (NullFieldException nfex) {
		throw new NullKeyFieldException(nfex);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(keyPositions[i]);
	}
}
 
Example #22
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setReference(T toCompare) {
	int i = 0;
	try {
		for (; i < this.keyPositions.length; i++) {
			this.comparators[i].setReference(toCompare.getFieldNotNull(this.keyPositions[i]));
		}
	}
	catch (NullFieldException nfex) {
		throw new NullKeyFieldException(nfex);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(keyPositions[i]);
	}
}
 
Example #23
Source File: OutputEmitterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int hash(Record object) {
	int i = 0;
	try {
		int code = 0;
		for (; i < this.keyFields.length; i++) {
			code ^= object.getField(this.keyFields[i], this.transientKeyHolders[i]).hashCode();
			code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component
		}
		return code;
	}
	catch (NullPointerException npex) {
		throw new NullKeyFieldException(this.keyFields[i]);
	}
	catch (IndexOutOfBoundsException iobex) {
		throw new KeyFieldOutOfBoundsException(this.keyFields[i]);
	}
}
 
Example #25
Source File: TupleComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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++) {
			code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt 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]);
	}
}
 
Example #26
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #27
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int compareSerialized(DataInputView source1, DataInputView source2) throws IOException {
	this.temp1.read(source1);
	this.temp2.read(source2);
	
	for (int i = 0; i < this.keyFields.length; i++) {
		@SuppressWarnings("rawtypes")
		final Comparable k1 = (Comparable) this.temp1.getField(this.keyFields[i], this.keyHolders[i]);
		@SuppressWarnings("rawtypes")
		final Comparable k2 = (Comparable) this.temp2.getField(this.keyFields[i], this.transientKeyHolders[i]);
		
		if (k1 == null || k2 == null) {
			throw new NullKeyFieldException(this.keyFields[i]);
		}
		
		@SuppressWarnings("unchecked")
		final int comp = k1.compareTo(k2);
		if (comp != 0) {
			return this.ascending[i] ? comp : -comp;
		}
	}
	return 0;
}
 
Example #28
Source File: RecordComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #29
Source File: TupleComparatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@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]);
	}
}
 
Example #30
Source File: RecordPairComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compareToReference(Record candidate) {
	for (int i = 0; i < this.keyFields2.length; i++) {
		final Comparable k = (Comparable) candidate.getField(this.keyFields2[i], this.keyHolders2[i]);
		if (k == null) {
			throw new NullKeyFieldException(this.keyFields2[i]);
		} else {
			final int comp = k.compareTo(this.keyHolders1[i]);
			if (comp != 0) {
				return comp;
			}
		}
	}
	return 0;
}