Rushikesh Gulve
06/06/2025, 9:12 AMimport org.apache.flink.runtime.state.KeyGroupRangeAssignment;
public class FlinkKeyGroupMapper {
public static void main(String[] args) {
final int maxParallelism = 128; // Flink maxParallelism
final int parallelism = 10; // Number of subtasks
final int keysNeeded = parallelism;
// Map: subtask index -> key found
java.util.Map<Integer, String> subtaskToKey = new java.util.HashMap<>();
int i = 100;
int configId = 20003;
while (subtaskToKey.size() < keysNeeded) {
String key = configId + "_" + i;
// Compute key group for this key (Flink does MurmurHash inside)
int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(key, maxParallelism);
// Find which operator subtask the key group maps to
int subtaskIndex = KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(
maxParallelism, parallelism, keyGroup);
// If this subtask index not assigned a key, assign it
if (!subtaskToKey.containsKey(subtaskIndex)) {
subtaskToKey.put(subtaskIndex, key);
System.out.println("Subtask " + subtaskIndex + " -> Key: " + key);
}
i++;
}
}
}
this is how I have generated the keys, and my key selector in flink also uses the same key. Can anyone guide me in how can I determine which parallel instance of subtask my current key should be redirected to? ThanksFrantisek Hartman
06/06/2025, 11:26 AMshuffle(), rebalance() or rescale() rather than generate keys in such a weird way