ss_everywhere
ss_everywhere

Reputation: 479

Flink custom partitioner example

The use case that I am trying to tackle is as follows:

So for example :

Questions:

  1. Will a custom partitioner help with this?
  2. If not what would be a good solution for this?
  3. Can someone share an example of a Custom partitioner in Flink for a Datastream. I was not able to find any complete examples.

Upvotes: 1

Views: 1654

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62285

A custom partitioner would help, but it is not necessary for you case.

You can just extract the grouping value from you messages and use it as grouping-key. Thus, after the sources read the data, you use a map to extract the value (eg, Record -> (groupingValue, Record) with data types byte[] -> Tuple2<keyType,byte[]> if you want to keep the raw message). Afterwards, you can use .keyBy(0) and apply whatever operator you want on it. keyBy ensures, that all records with the same value in the first field of Tuple2 are processed by the same operator.

Upvotes: 2

Related Questions