The default partitioner takes a hash of the key of a topic to determine the
partition number.
It would be useful for a key to be able to specify the object on which the
default partitioner should base its hash on. This would allow us to use
different composite keys and still be certain that they arrive on the same
partition.
For example: I have 2 topics. One keys with a composite key containing a
student with its classRoom. The other one is keyed with a treacher and its
classRoom.
I want to make sure both end up in the same partition, even though they have
different keys. However, they share the same classRoom.
I can create a custom partitioner where I specifically partition by classRoom,
but things break down when using kafka-streams because kafka-streams always
uses the default partitioner for internal repartitioning during maps, joins,
etc....
Would it be a useful idea to allow keys to implement a well-known interface
like the following:
interface PartitionKeyAware{
Object partitionKey()
}
The default partitioner could then look for objects of that type and call the
partitionKey to do its hash.
Or is this a really bad idea not worth the effort to put it in a KIP?