@Override
  public Map<TaskName, Set<SystemStreamPartition>> group(Set<SystemStreamPartition> ssps) {
    Map<TaskName, Set<SystemStreamPartition>> groupedMap = new HashMap<>();

    for (SystemStreamPartition ssp : ssps) {
      // Broadcast streams are part of all the tasks. They are added to each task at the end.
      if (broadcastStreams.contains(ssp)) {
        continue;
      }

      // if elasticity factor > 1 then elasticity is enabled
      // for each partition create ElasticityFactor number of tasks
      // i.e; result will have number of tasks =  ElasticityFactor X number of partitions
      // each task will have name Partition_X_Y where X is the partition number and Y <= elasticityFactor
      // each task Partition_X_Y consumes the keyBucket Y of all the SSP with partition number X.
      for (int i = 0; i < elasticityFactor; i++) {
        int keyBucket = elasticityFactor == 1 ? -1 : i;
        String taskNameStr = elasticityFactor == 1 ?
            String.format("Partition %d", ssp.getPartition().getPartitionId()) :
            String.format("Partition %d %d", ssp.getPartition().getPartitionId(), keyBucket);
        TaskName taskName = new TaskName(taskNameStr);
        SystemStreamPartition sspWithKeyBucket = new SystemStreamPartition(ssp, keyBucket);
        groupedMap.putIfAbsent(taskName, new HashSet<>());
        groupedMap.get(taskName).add(sspWithKeyBucket);
      }
    }

    // assign the broadcast streams to all the taskNames
    if (!broadcastStreams.isEmpty()) {
      for (Set<SystemStreamPartition> value : groupedMap.values()) {
        value.addAll(broadcastStreams);
      }
    }

    return groupedMap;
  }
An implementation of {@link SystemStreamPartitionGrouper} that groups the input stream partitions according to their partition number.
This leads to a single task processing all the messages of a single partition (e.g. partition 0) across all the input streams.
Using this strategy, if two input streams have a partition 0, then all the messages from both partitions will be routed to a single task.
This partitioning strategy is useful for joining and aggregating input streams.
samza-core/src/main/java/org/apache/samza/container/grouper/stream/GroupByPartition.java