org.apache.flink.types.NormalizableKey Java Examples

The following examples show how to use org.apache.flink.types.NormalizableKey. 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: 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 #2
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 #3
Source File: WritableComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	ensureReferenceInstantiated();

	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #4
Source File: WritableComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	ensureReferenceInstantiated();

	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #5
Source File: WritableComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	ensureReferenceInstantiated();

	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #6
Source File: GenericTypeComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	if (this.reference == null) {
		this.reference = InstantiationUtil.instantiate(this.type);
	}

	NormalizableKey<?> key = (NormalizableKey<?>) this.reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #7
Source File: GenericTypeComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	if (this.reference == null) {
		this.reference = InstantiationUtil.instantiate(this.type);
	}

	NormalizableKey<?> key = (NormalizableKey<?>) this.reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #8
Source File: ValueComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	if (reference == null) {
		reference = InstantiationUtil.instantiate(type, Value.class);
	}
	
	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #9
Source File: ValueComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	if (reference == null) {
		reference = InstantiationUtil.instantiate(type, Value.class);
	}
	
	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #10
Source File: WritableComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(type);
}
 
Example #11
Source File: NullValueArrayComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(NullValueArray.class);
}
 
Example #12
Source File: RecordComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new comparator that compares Pact Records by the subset of fields as described
 * by the given key positions and types.
 * 
 * @param keyFields The positions of the key fields.
 * @param keyTypes The types (classes) of the key fields.
 * @param sortDirection The direction for sorting. A value of <i>true</i> indicates ascending for an attribute,
 *                  a value of <i>false</i> indicated descending. If the parameter is <i>null</i>, then
 *                  all order comparisons will assume ascending order on all fields.
 */
public RecordComparator(int[] keyFields, Class<? extends Value>[] keyTypes, boolean[] sortDirection) {
	this.keyFields = keyFields;
	
	// instantiate fields to extract keys into
	this.keyHolders = new Value[keyTypes.length];
	this.transientKeyHolders = new Value[keyTypes.length];
	for (int i = 0; i < keyTypes.length; i++) {
		if (keyTypes[i] == null) {
			throw new NullPointerException("Key type " + i + " is null.");
		}
		this.keyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
		this.transientKeyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
	}
	
	// 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.keyHolders.length; i++) {
		Value k = this.keyHolders[i];
		if (k instanceof NormalizableKey) {
			if (sortDirection != null) {
				if (sortDirection[i] && inverted) {
					break;
				} else if (i == 0 && !sortDirection[0]) {
					inverted = true;
				}
			}
			nKeys++;
			final int len = ((NormalizableKey) k).getMaxNormalizedKeyLen();
			if (len < 0) {
				throw new RuntimeException("Data type " + k.getClass().getName() + 
					" specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += this.normalizedKeyLengths[i];
			if (nKeyLen < 0) {
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	
	this.temp1 = new Record();
	this.temp2 = new Record();
	
	if (sortDirection != null) {
		this.ascending = sortDirection;
	} else {
		this.ascending = new boolean[keyFields.length];
		for (int i = 0; i < this.ascending.length; i++) {
			this.ascending[i] = true;
		}
	}
}
 
Example #13
Source File: RecordComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new comparator that compares Pact Records by the subset of fields as described
 * by the given key positions and types.
 * 
 * @param keyFields The positions of the key fields.
 * @param keyTypes The types (classes) of the key fields.
 * @param sortDirection The direction for sorting. A value of <i>true</i> indicates ascending for an attribute,
 *                  a value of <i>false</i> indicated descending. If the parameter is <i>null</i>, then
 *                  all order comparisons will assume ascending order on all fields.
 */
public RecordComparator(int[] keyFields, Class<? extends Value>[] keyTypes, boolean[] sortDirection) {
	this.keyFields = keyFields;
	
	// instantiate fields to extract keys into
	this.keyHolders = new Value[keyTypes.length];
	this.transientKeyHolders = new Value[keyTypes.length];
	for (int i = 0; i < keyTypes.length; i++) {
		if (keyTypes[i] == null) {
			throw new NullPointerException("Key type " + i + " is null.");
		}
		this.keyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
		this.transientKeyHolders[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
	}
	
	// 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.keyHolders.length; i++) {
		Value k = this.keyHolders[i];
		if (k instanceof NormalizableKey) {
			if (sortDirection != null) {
				if (sortDirection[i] && inverted) {
					break;
				} else if (i == 0 && !sortDirection[0]) {
					inverted = true;
				}
			}
			nKeys++;
			final int len = ((NormalizableKey) k).getMaxNormalizedKeyLen();
			if (len < 0) {
				throw new RuntimeException("Data type " + k.getClass().getName() + 
					" specifies an invalid length for the normalized key: " + len);
			}
			this.normalizedKeyLengths[i] = len;
			nKeyLen += this.normalizedKeyLengths[i];
			if (nKeyLen < 0) {
				nKeyLen = Integer.MAX_VALUE;
				break;
			}
		} else {
			break;
		}
	}
	this.numLeadingNormalizableKeys = nKeys;
	this.normalizableKeyPrefixLen = nKeyLen;
	
	this.temp1 = new Record();
	this.temp2 = new Record();
	
	if (sortDirection != null) {
		this.ascending = sortDirection;
	} else {
		this.ascending = new boolean[keyFields.length];
		for (int i = 0; i < this.ascending.length; i++) {
			this.ascending[i] = true;
		}
	}
}
 
Example #14
Source File: StringValueArrayComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(StringValueArray.class);
}
 
Example #15
Source File: FloatValueArrayComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(FloatValueArray.class);
}
 
Example #16
Source File: IntValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(IntValue.class);
}
 
Example #17
Source File: ByteValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(ByteValue.class);
}
 
Example #18
Source File: CharValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(CharValue.class);
}
 
Example #19
Source File: ByteValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(ByteValue.class);
}
 
Example #20
Source File: NullValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(NullValue.class);
}
 
Example #21
Source File: FloatValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void putNormalizedKey(FloatValue record, MemorySegment target, int offset, int numBytes) {
	NormalizableKey<?> key = (NormalizableKey<?>) record;
	key.copyNormalizedKey(target, offset, numBytes);
}
 
Example #22
Source File: FloatValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #23
Source File: FloatValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(FloatValue.class);
}
 
Example #24
Source File: NullValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(NullValue.class);
}
 
Example #25
Source File: BooleanValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(BooleanValue.class);
}
 
Example #26
Source File: CopyableValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void putNormalizedKey(T record, MemorySegment target, int offset, int numBytes) {
	NormalizableKey<?> key = (NormalizableKey<?>) record;
	key.copyNormalizedKey(target, offset, numBytes);
}
 
Example #27
Source File: CopyableValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int getNormalizeKeyLen() {
	NormalizableKey<?> key = (NormalizableKey<?>) reference;
	return key.getMaxNormalizedKeyLen();
}
 
Example #28
Source File: CopyableValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(type);
}
 
Example #29
Source File: CharValueArrayComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(CharValueArray.class);
}
 
Example #30
Source File: CopyableValueComparator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsNormalizedKey() {
	return NormalizableKey.class.isAssignableFrom(type);
}