...
Motivation
Kafka Streams methods to that apply transformations to KStreams, KTtables, etc. are currently invariant in their parameterized key and value types, when they should probably be contravariant in those types. For instance, KStream.filter(Predicate<K, V> predicate) should be KStream.filter(Predicate<? super K, ? super V> predicate) to accept predicates that can act on any supertype of K, or V.
...
The same reasoning applies to the key and value types used in methods that take Aggregator, StreamPartitioner, KeyValueMapper, ValueMapper, ProcessorSupplier, and ValueJoiner.
Public Interfaces
Affected methods | current argument type | new argument type |
---|---|---|
(KGroupedStream|KGroupedTable).aggregate | Aggregator<K, V, T> | Aggregator<? super K, ? super V, T> |
(KTable|KStream).(filter*|branch) | Predicate<K, V> | Predicate<? super K, ? super V> |
(KStream).(selectKey|map|flatMap|groupBy) | KeyValueMapper<K, V, X> | KeyValueMapper<? super K, ? super V, X> |
(KStream).(mapValues|flatMapValues) | KeyValueMapper<V, X> | ValueMapper<? super V, X> |
KStream.transform | TransformerSupplier<K, V, X> | TransformerSupplier<? super K, ? super V, X> |
KStream.transformValues | ValueTransformerSupplier<V, X> | ValueTransformerSupplier<? super V, X> |
KStream.foreach | ForeachAction<K, V> | ForeachAction<? super K, ? super V> |
KStream.process | ProcessorSupplier<K, V> | ProcessorSupplier<? super K, ? super V> |
KStream.*join | ValueJoiner<K, V, R> | ValueJoiner<? super K, ? super V, R> |
KStream.(to|through) | StreamPartitioner<K, V> | StreamPartitioner<? super K, ? super V> |
All methods will have their arguments changed to
All methods will have their arguments changed to
KStream.to
Briefly list any new interfaces that will be introduced as part of this proposal or any existing interfaces that will be removed or changed. The purpose of this section is to concisely call out the public contract that will come along with this feature.
A public interface is any change to the following:
Binary log format
The network protocol and api behavior
Any class in the public packages under clientsConfiguration, especially client configuration
org/apache/kafka/common/serialization
org/apache/kafka/common
org/apache/kafka/common/errors
org/apache/kafka/clients/producer
org/apache/kafka/clients/consumer (eventually, once stable)
Monitoring
Command line tools and arguments
- Anything else that will likely break existing users in some way when they upgrade
...