org.apache.flink.runtime.state.KeyGroupPartitioner Java Examples

The following examples show how to use org.apache.flink.runtime.state.KeyGroupPartitioner. 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: StateTableKeyGroupPartitionerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected KeyGroupPartitioner<StateTableEntry<Integer, VoidNamespace, Integer>> createPartitioner(
	StateTableEntry<Integer, VoidNamespace, Integer>[] data,
	int numElements,
	KeyGroupRange keyGroupRange,
	int totalKeyGroups,
	KeyGroupPartitioner.ElementWriterFunction<
		StateTableEntry<Integer, VoidNamespace, Integer>> elementWriterFunction) {

	return new CopyOnWriteStateTableSnapshot.StateTableKeyGroupPartitioner<>(
		data,
		numElements,
		keyGroupRange,
		totalKeyGroups,
		elementWriterFunction);
}
 
Example #2
Source File: HeapPriorityQueueSnapshotRestoreWrapper.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateSnapshotKeyGroupReader keyGroupReader(int readVersionHint) {
	final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();
	return KeyGroupPartitioner.createKeyGroupPartitionReader(
		elementSerializer::deserialize, //we know that this does not deliver nulls, because we never write nulls
		(element, keyGroupId) -> priorityQueue.add(element));
}
 
Example #3
Source File: StateTableByKeyGroupReaders.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static <K, N, S> StateSnapshotKeyGroupReader createV2PlusReader(StateTable<K, N, S> stateTable) {
	final TypeSerializer<K> keySerializer = stateTable.keyContext.getKeySerializer();
	final TypeSerializer<N> namespaceSerializer = stateTable.getNamespaceSerializer();
	final TypeSerializer<S> stateSerializer = stateTable.getStateSerializer();
	final Tuple3<N, K, S> buffer = new Tuple3<>();
	return KeyGroupPartitioner.createKeyGroupPartitionReader((in) -> {
		buffer.f0 = namespaceSerializer.deserialize(in);
		buffer.f1 = keySerializer.deserialize(in);
		buffer.f2 = stateSerializer.deserialize(in);
		return buffer;
	}, (element, keyGroupId1) -> stateTable.put(element.f1, keyGroupId1, element.f0, element.f2));
}
 
Example #4
Source File: HeapPriorityQueueStateSnapshot.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public StateKeyGroupWriter getKeyGroupWriter() {

	if (stateKeyGroupWriter == null) {

		T[] partitioningOutput = (T[]) Array.newInstance(
			heapArrayCopy.getClass().getComponentType(),
			heapArrayCopy.length);

		final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();

		KeyGroupPartitioner<T> keyGroupPartitioner =
			new KeyGroupPartitioner<>(
				heapArrayCopy,
				heapArrayCopy.length,
				partitioningOutput,
				keyGroupRange,
				totalKeyGroups,
				keyExtractor,
				elementSerializer::serialize);

		stateKeyGroupWriter = keyGroupPartitioner.partitionByKeyGroup();
	}

	return stateKeyGroupWriter;
}
 
Example #5
Source File: HeapPriorityQueueSnapshotRestoreWrapper.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateSnapshotKeyGroupReader keyGroupReader(int readVersionHint) {
	final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();
	return KeyGroupPartitioner.createKeyGroupPartitionReader(
		elementSerializer::deserialize, //we know that this does not deliver nulls, because we never write nulls
		(element, keyGroupId) -> priorityQueue.add(element));
}
 
Example #6
Source File: StateTableByKeyGroupReaders.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <K, N, S> StateSnapshotKeyGroupReader createV2PlusReader(
	StateTable<K, N, S> stateTable) {
	final TypeSerializer<N> namespaceSerializer = stateTable.getNamespaceSerializer();
	final TypeSerializer<S> stateSerializer = stateTable.getStateSerializer();
	final TypeSerializer<K> keySerializer = stateTable.keySerializer;
	final Tuple3<N, K, S> buffer = new Tuple3<>();
	return KeyGroupPartitioner.createKeyGroupPartitionReader((in) -> {
		buffer.f0 = namespaceSerializer.deserialize(in);
		buffer.f1 = keySerializer.deserialize(in);
		buffer.f2 = stateSerializer.deserialize(in);
		return buffer;
	}, (element, keyGroupId1) -> stateTable.put(element.f1, keyGroupId1, element.f0, element.f2));
}
 
Example #7
Source File: HeapPriorityQueueStateSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public StateKeyGroupWriter getKeyGroupWriter() {

	if (stateKeyGroupWriter == null) {

		T[] partitioningOutput = (T[]) Array.newInstance(
			heapArrayCopy.getClass().getComponentType(),
			heapArrayCopy.length);

		final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();

		KeyGroupPartitioner<T> keyGroupPartitioner =
			new KeyGroupPartitioner<>(
				heapArrayCopy,
				heapArrayCopy.length,
				partitioningOutput,
				keyGroupRange,
				totalKeyGroups,
				keyExtractor,
				elementSerializer::serialize);

		stateKeyGroupWriter = keyGroupPartitioner.partitionByKeyGroup();
	}

	return stateKeyGroupWriter;
}
 
Example #8
Source File: HeapPriorityQueueSnapshotRestoreWrapper.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public StateSnapshotKeyGroupReader keyGroupReader(int readVersionHint) {
	final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();
	return KeyGroupPartitioner.createKeyGroupPartitionReader(
		elementSerializer::deserialize, //we know that this does not deliver nulls, because we never write nulls
		(element, keyGroupId) -> priorityQueue.add(element));
}
 
Example #9
Source File: StateTableByKeyGroupReaders.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <K, N, S> StateSnapshotKeyGroupReader createV2PlusReader(
	StateTable<K, N, S> stateTable) {
	final TypeSerializer<N> namespaceSerializer = stateTable.getNamespaceSerializer();
	final TypeSerializer<S> stateSerializer = stateTable.getStateSerializer();
	final TypeSerializer<K> keySerializer = stateTable.keySerializer;
	final Tuple3<N, K, S> buffer = new Tuple3<>();
	return KeyGroupPartitioner.createKeyGroupPartitionReader((in) -> {
		buffer.f0 = namespaceSerializer.deserialize(in);
		buffer.f1 = keySerializer.deserialize(in);
		buffer.f2 = stateSerializer.deserialize(in);
		return buffer;
	}, (element, keyGroupId1) -> stateTable.put(element.f1, keyGroupId1, element.f0, element.f2));
}
 
Example #10
Source File: HeapPriorityQueueStateSnapshot.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public StateKeyGroupWriter getKeyGroupWriter() {

	if (stateKeyGroupWriter == null) {

		T[] partitioningOutput = (T[]) Array.newInstance(
			heapArrayCopy.getClass().getComponentType(),
			heapArrayCopy.length);

		final TypeSerializer<T> elementSerializer = metaInfo.getElementSerializer();

		KeyGroupPartitioner<T> keyGroupPartitioner =
			new KeyGroupPartitioner<>(
				heapArrayCopy,
				heapArrayCopy.length,
				partitioningOutput,
				keyGroupRange,
				totalKeyGroups,
				keyExtractor,
				elementSerializer::serialize);

		stateKeyGroupWriter = keyGroupPartitioner.partitionByKeyGroup();
	}

	return stateKeyGroupWriter;
}