Java Code Examples for org.apache.flink.runtime.state.KeyGroupRangeAssignment#computeOperatorIndexForKeyGroup()

The following examples show how to use org.apache.flink.runtime.state.KeyGroupRangeAssignment#computeOperatorIndexForKeyGroup() . 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: FlinkUtils.java    From flink-crawler with Apache License 2.0 6 votes vote down vote up
/**
 * Return an integer value that will get partitioned to the target <operatorIndex>, given the workflow's
 * <maxParallelism> (for key groups) and the operator <parallelism>.
 * 
 * @param maxParallelism
 * @param parallelism
 * @param operatorIndex
 * @return Integer suitable for use in a record as the key.
 */
public static Integer makeKeyForOperatorIndex(int maxParallelism, int parallelism,
        int operatorIndex) {
    if (maxParallelism == ExecutionJobVertex.VALUE_NOT_SET) {
        maxParallelism = KeyGroupRangeAssignment.computeDefaultMaxParallelism(parallelism);
    }

    for (int i = 0; i < maxParallelism * 2; i++) {
        Integer key = new Integer(i);
        int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(key, maxParallelism);
        int index = KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(maxParallelism,
                parallelism, keyGroup);
        if (index == operatorIndex) {
            return key;
        }
    }

    throw new RuntimeException(String.format(
            "Unable to find key for target operator index %d (max parallelism = %d, parallelism = %d",
            operatorIndex, maxParallelism, parallelism));
}
 
Example 2
Source File: KeyGroupRangePartitioner.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int partition(Integer key, int numPartitions) {
	return KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(
		maxParallelism,
		numPartitions,
		KeyGroupRangeAssignment.computeKeyGroupForKeyHash(key, maxParallelism));
}
 
Example 3
Source File: KeyGroupRangePartitioner.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int partition(Integer key, int numPartitions) {
	return KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(
		maxParallelism,
		numPartitions,
		KeyGroupRangeAssignment.computeKeyGroupForKeyHash(key, maxParallelism));
}
 
Example 4
Source File: KeyedStateRow.java    From bravo with Apache License 2.0 4 votes vote down vote up
public Integer getOperatorIndex(int maxParallelism, int parallelism) throws Exception {
	return KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(maxParallelism, parallelism,
			getKeyGroup(maxParallelism));
}
 
Example 5
Source File: FlinkUtils.java    From flink-crawler with Apache License 2.0 4 votes vote down vote up
public static int getOperatorIndexForKey(String key, int maxParallelism, int parallelism) {
    int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(key, maxParallelism);
    return KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(maxParallelism,
            parallelism, keyGroup);
}