Make things more consistant and add Materialized helper with implicit Serdes#69
Make things more consistant and add Materialized helper with implicit Serdes#69joan38 wants to merge 2 commits into
Conversation
| import org.apache.kafka.streams.processor.StateStore | ||
| import org.apache.kafka.streams.state._ | ||
|
|
||
| object MaterializedS { |
There was a problem hiding this comment.
Maybe we can just name this Materialized? I don't think it would conflict if we import org.apache.kafka.streams.kstream.{Materialized => JavaMaterialized
8448c2c to
4922680
Compare
|
@debasishg I think |
|
Hi @debasishg, I know you're quite busy but do you know if you'll be able to have a look anytime soon? |
|
I will surely look at them tomorrow. It's past midnight in my part of the world. Sorry for the delay. |
|
Thanks @debasishg |
| def reduce(reducer: (V, V) => V, | ||
| materialized: Materialized[K, V, KeyValueStore[Bytes, Array[Byte]]]): KTableS[K, V] = { | ||
| def count()(implicit materialized: Materialized[K, Long, KeyValueStore[Bytes, Array[Byte]]]): KTableS[K, Long] = | ||
| inner.count(materialized.asInstanceOf[Materialized[K, java.lang.Long, KeyValueStore[Bytes, Array[Byte]]]]).asInstanceOf[KTable[K, Long]] |
There was a problem hiding this comment.
This will not work. count() that does not take a Materialized should not materialize to any store.
|
I went through the changes. Implicit Materialized is something that won't work - we had a long discussion on this before. For APIs like count(), reduce() etc. there is a variant that does not materialize to stores. Also converting serdes to Materialized implicitly is not safe since Materialized can take lots of other parameters etc. caching, logging etc. which will have to be provided separately. |
|
If I look at the API documentation of
To me it's actually materializing to a store using the default serdes. And this will break at runtime if the default serdes are not the right ones. The overall idea was that you have a default |
7d4c053 to
d15f4bf
Compare
This result is the count value, which is |
|
I think you are right this would probably be useful for Instead we may provide a tiny helper for creating |
|
This can now be closed as it's been opened on Kafka's repo with apache/kafka#4966 |
This helps on making the whole thing more typesafe since we use implicitly resolved
Materialized.Also this contains a change on the
counts to useMaterializedinstead of thestateStore: Stringwhich is deprecated on the underlying Java API since for example it doesn't allow to configure caching.Instead of mapping the values to convert them to
scala.Longwe can just cast the top type directly. This should save a tiny on performances.