Example of the modulus partitioner
In this example, the modulus partitioner partitions a data set containing ten records. Four processing nodes run the partitioner, and the modulus partitioner divides the data among four partitions.
The input interface schema is as follows:
a:uint32; date:date;
Field a, of type uint32, is specified as the key field, on which the modulus operation is calculated.
Here is the input data set. Each line represents a record:
64123 1960-03-30
61821 1960-06-27
44919 1961-06-18
22677 1960-09-24
90746 1961-09-15
21870 1960-01-01
87702 1960-12-22
4705 1961-12-13
47330 1961-03-21
88193 1962-03-12
The following table shows the output data set divided among four partitions by the modulus partitioner.
| Partition 0 | Partition1 | Partition2 | Partion3 |
|---|---|---|---|
61821 1960-06-27 22677
|
21870 1960-01-01
|
64123 1960-03-30
|
Here are three sample modulus operations, corresponding to the values of the three key fields shown above with underscore:
22677 mod 4 = 1; the data is written to Partition 1.
47330 mod 4 = 2; the data is written to Partition 2.
64123 mod 4 = 3; the data is written to Partition 3.
None of the key fields can be divided evenly by 4, so no data is written to Partition 0.