Java Code Examples for org.apache.flink.api.common.typeutils.TypeComparator#supportsNormalizedKey()

The following examples show how to use org.apache.flink.api.common.typeutils.TypeComparator#supportsNormalizedKey() . 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: TupleComparatorBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TupleComparatorBase(int[] keyPositions, TypeComparator<?>[] comparators, TypeSerializer<?>[] serializers) {
	// set the default utils
	this.keyPositions = keyPositions;
	this.comparators = (TypeComparator<Object>[]) comparators;
	this.serializers = (TypeSerializer<Object>[]) serializers;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyPositions.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.keyPositions.length; i++) {
		TypeComparator<?> k = this.comparators[i];

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += len;

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}
 
Example 2
Source File: PojoComparator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public PojoComparator(Field[] keyFields, TypeComparator<?>[] comparators, TypeSerializer<T> serializer, Class<T> type) {
	this.keyFields = keyFields;
	this.comparators = (TypeComparator<Object>[]) comparators;

	this.type = type;
	this.serializer = serializer;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyFields.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.comparators.length; i++) {
		TypeComparator<?> k = this.comparators[i];
		if(k == null) {
			throw new IllegalArgumentException("One of the passed comparators is null");
		}
		if(keyFields[i] == null) {
			throw new IllegalArgumentException("One of the passed reflection fields is null");
		}

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += this.normalizedKeyLengths[i];

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}
 
Example 3
Source File: TupleComparatorBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TupleComparatorBase(int[] keyPositions, TypeComparator<?>[] comparators, TypeSerializer<?>[] serializers) {
	// set the default utils
	this.keyPositions = keyPositions;
	this.comparators = (TypeComparator<Object>[]) comparators;
	this.serializers = (TypeSerializer<Object>[]) serializers;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyPositions.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.keyPositions.length; i++) {
		TypeComparator<?> k = this.comparators[i];

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += len;

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}
 
Example 4
Source File: PojoComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public PojoComparator(Field[] keyFields, TypeComparator<?>[] comparators, TypeSerializer<T> serializer, Class<T> type) {
	this.keyFields = keyFields;
	this.comparators = (TypeComparator<Object>[]) comparators;

	this.type = type;
	this.serializer = serializer;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyFields.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.comparators.length; i++) {
		TypeComparator<?> k = this.comparators[i];
		if(k == null) {
			throw new IllegalArgumentException("One of the passed comparators is null");
		}
		if(keyFields[i] == null) {
			throw new IllegalArgumentException("One of the passed reflection fields is null");
		}

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += this.normalizedKeyLengths[i];

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}
 
Example 5
Source File: UnknownTupleComparator.java    From cascading-flink with Apache License 2.0 4 votes vote down vote up
public UnknownTupleComparator(int[] keyPositions, TypeComparator<?>[] comparators, TypeSerializer<?> serializer) {

		this.keyPositions = keyPositions;
		this.comparators = comparators;
		this.serializer = serializer;

		// set up auxiliary fields for normalized key support
		this.normalizedKeyLengths = new int[keyPositions.length];
		int nKeys = 0;
		int nKeyLen = 0;
		boolean inverted = false;

		for (int i = 0; i < this.keyPositions.length; i++) {
			TypeComparator<?> k = this.comparators[i];

			// as long as the leading keys support normalized keys, we can build up the composite key
			if (k.supportsNormalizedKey()) {
				if (i == 0) {
					// the first comparator decides whether we need to invert the key direction
					inverted = k.invertNormalizedKey();
				}
				else if (k.invertNormalizedKey() != inverted) {
					// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
					break;
				}

				nKeys++;
				final int len = k.getNormalizeKeyLen();
				if (len < 0) {
					throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
				}
				this.normalizedKeyLengths[i] = len;
				nKeyLen += len;

				if (nKeyLen < 0) {
					// overflow, which means we are out of budget for normalized key space anyways
					nKeyLen = Integer.MAX_VALUE;
					break;
				}
			} else {
				break;
			}
		}
		this.numLeadingNormalizableKeys = nKeys;
		this.normalizableKeyPrefixLen = nKeyLen;
		this.invertNormKey = inverted;
	}
 
Example 6
Source File: DefinedTupleComparator.java    From cascading-flink with Apache License 2.0 4 votes vote down vote up
public DefinedTupleComparator(int[] keyPositions, TypeComparator<?>[] comparators, TypeSerializer<?>[] serializers, int tupleLength) {

		this.keyPositions = keyPositions;
		this.comparators = comparators;
		this.serializers = serializers;
		this.tupleLength = tupleLength;

		this.fields1 = new Object[serializers.length];
		this.fields2 = new Object[serializers.length];
		this.nullFields1 = new boolean[this.tupleLength];
		this.nullFields2 = new boolean[this.tupleLength];

		// set up auxiliary fields for normalized key support
		this.normalizedKeyLengths = new int[keyPositions.length];
		int nKeys = 0;
		int nKeyLen = 0;
		boolean inverted = false;

		for (int i = 0; i < this.keyPositions.length; i++) {
			TypeComparator<?> k = this.comparators[i];

			// as long as the leading keys support normalized keys, we can build up the composite key
			if (k.supportsNormalizedKey()) {
				if (i == 0) {
					// the first comparator decides whether we need to invert the key direction
					inverted = k.invertNormalizedKey();
				}
				else if (k.invertNormalizedKey() != inverted) {
					// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
					break;
				}

				nKeys++;
				final int len = k.getNormalizeKeyLen();
				if (len < 0) {
					throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
				}
				this.normalizedKeyLengths[i] = len;
				nKeyLen += len;

				if (nKeyLen < 0) {
					// overflow, which means we are out of budget for normalized key space anyways
					nKeyLen = Integer.MAX_VALUE;
					break;
				}
			} else {
				break;
			}
		}
		this.numLeadingNormalizableKeys = nKeys;
		this.normalizableKeyPrefixLen = nKeyLen;
		this.invertNormKey = inverted;
	}
 
Example 7
Source File: TupleComparatorBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TupleComparatorBase(int[] keyPositions, TypeComparator<?>[] comparators, TypeSerializer<?>[] serializers) {
	// set the default utils
	this.keyPositions = keyPositions;
	this.comparators = (TypeComparator<Object>[]) comparators;
	this.serializers = (TypeSerializer<Object>[]) serializers;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyPositions.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.keyPositions.length; i++) {
		TypeComparator<?> k = this.comparators[i];

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += len;

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}
 
Example 8
Source File: PojoComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public PojoComparator(Field[] keyFields, TypeComparator<?>[] comparators, TypeSerializer<T> serializer, Class<T> type) {
	this.keyFields = keyFields;
	this.comparators = (TypeComparator<Object>[]) comparators;

	this.type = type;
	this.serializer = serializer;

	// set up auxiliary fields for normalized key support
	this.normalizedKeyLengths = new int[keyFields.length];
	int nKeys = 0;
	int nKeyLen = 0;
	boolean inverted = false;

	for (int i = 0; i < this.comparators.length; i++) {
		TypeComparator<?> k = this.comparators[i];
		if(k == null) {
			throw new IllegalArgumentException("One of the passed comparators is null");
		}
		if(keyFields[i] == null) {
			throw new IllegalArgumentException("One of the passed reflection fields is null");
		}

		// as long as the leading keys support normalized keys, we can build up the composite key
		if (k.supportsNormalizedKey()) {
			if (i == 0) {
				// the first comparator decides whether we need to invert the key direction
				inverted = k.invertNormalizedKey();
			}
			else if (k.invertNormalizedKey() != inverted) {
				// if a successor does not agree on the inversion direction, it cannot be part of the normalized key
				break;
			}

			nKeys++;
			final int len = k.getNormalizeKeyLen();
			if (len < 0) {
				throw new RuntimeException("Comparator " + k.getClass().getName() + " specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += this.normalizedKeyLengths[i];

			if (nKeyLen < 0) {
				// overflow, which means we are out of budget for normalized key space anyways
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	this.invertNormKey = inverted;
}