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
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 and Description |
---|
PartialKeyGrouping() |
PartialKeyGrouping(Fields fields) |
PartialKeyGrouping(Fields fields,
PartialKeyGrouping.AssignmentCreator assignmentCreator) |
PartialKeyGrouping(Fields fields,
PartialKeyGrouping.AssignmentCreator assignmentCreator,
PartialKeyGrouping.TargetSelector targetSelector) |
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.
|
public PartialKeyGrouping()
public PartialKeyGrouping(Fields fields)
public PartialKeyGrouping(Fields fields, PartialKeyGrouping.AssignmentCreator assignmentCreator)
public PartialKeyGrouping(Fields fields, PartialKeyGrouping.AssignmentCreator assignmentCreator, PartialKeyGrouping.TargetSelector targetSelector)
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks)
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.
prepare
in interface CustomStreamGrouping
public List<Integer> chooseTasks(int taskId, List<Object> values)
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.
chooseTasks
in interface CustomStreamGrouping
values
- the values to group onCopyright © 2019 The Apache Software Foundation. All rights reserved.