org.apache.storm.grouping

## Class PartialKeyGrouping

- java.lang.Object
- - org.apache.storm.grouping.PartialKeyGrouping

- All Implemented Interfaces:
    Serializable, CustomStreamGrouping

      public class PartialKeyGrouping
      extends Object
      implements CustomStreamGrouping, Serializable

  A variation on FieldGrouping. This grouping operates on a partitioning of the incoming tuples (like a FieldGrouping), but it can send Tuples from a given partition to multiple downstream tasks.

  Given a total pool of target tasks, this grouping will always send Tuples with a given key to one member of a subset of those tasks. Each key is assigned a subset of tasks. Each tuple is then sent to one task from that subset.

  Notes: - the default TaskSelector ensures each task gets as close to a balanced number of Tuples as possible - the default AssignmentCreator hashes the key and produces an assignment of two tasks

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `PartialKeyGrouping.AssignmentCreator` This interface is responsible for choosing a subset of the target tasks to use for a given key.
    `static class` | `PartialKeyGrouping.BalancedTargetSelector` A basic implementation of target selection.
    `static class` | `PartialKeyGrouping.RandomTwoTaskAssignmentCreator` This implementation of AssignmentCreator chooses two arbitrary tasks.
    `static interface` | `PartialKeyGrouping.TargetSelector` This interface chooses one element from a task assignment to send a specific Tuple to.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PartialKeyGrouping()`
    `PartialKeyGrouping(Fields fields)`
    `PartialKeyGrouping(Fields fields, PartialKeyGrouping.AssignmentCreator assignmentCreator)`
    `PartialKeyGrouping(Fields fields, PartialKeyGrouping.AssignmentCreator assignmentCreator, PartialKeyGrouping.TargetSelector targetSelector)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<Integer>` | `chooseTasks(int taskId, List<Object> values)` This function implements a custom stream grouping.
    `void` | `prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks)` Tells the stream grouping at runtime the tasks in the target bolt.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PartialKeyGrouping

          public PartialKeyGrouping()

    - #### PartialKeyGrouping

          public PartialKeyGrouping(Fields fields)

    - #### PartialKeyGrouping

          public PartialKeyGrouping(Fields fields,
                                    PartialKeyGrouping.AssignmentCreator assignmentCreator)

    - #### PartialKeyGrouping

          public PartialKeyGrouping(Fields fields,
                                    PartialKeyGrouping.AssignmentCreator assignmentCreator,
                                    PartialKeyGrouping.TargetSelector targetSelector)

  - ### Method Detail

    - #### prepare

          public void prepare(WorkerTopologyContext context,
                              GlobalStreamId stream,
                              List<Integer> targetTasks)

      Description copied from interface: `CustomStreamGrouping`

      Tells the stream grouping at runtime the tasks in the target bolt. This information should be used in chooseTasks to determine the target tasks.

      It also tells the grouping the metadata on the stream this grouping will be used on.

      Specified by:
        `prepare` in interface `CustomStreamGrouping`

    - #### chooseTasks

          public List<Integer> chooseTasks(int taskId,
                                           List<Object> values)

      Description copied from interface: `CustomStreamGrouping`

      This function implements a custom stream grouping. It takes in as input the number of tasks in the target bolt in prepare and returns the tasks to send the tuples to.

      Specified by:
        `chooseTasks` in interface `CustomStreamGrouping`
        `values` - the values to group on

Copyright © 2021 The Apache Software Foundation. All rights reserved.