Use ValueTransformerWithKey instead of Transformer#292
Conversation
|
Concerning the need of |
|
Hi Ivan Ponomarev (@inponomarev), Thanks for the PR. Yes, you are correct in the usage of a
Thanks for pointing that out. But it seems the JavaDocs were in error, and this merged PR apache/kafka#8298 corrects the issue. So you'll still need to use a |
|
Hi Bill Bejeck (@bbejeck) sorry for delay with this, I have updated the tutorial. Concerning the nulls in |
Bill Bejeck (bbejeck)
left a comment
There was a problem hiding this comment.
Thanks, Ivan Ponomarev (@inponomarev) looks good overall some text updates are needed for rendering purposes.
| Focusing on the `buildTopology` method, note how the Kafka Streams topology relies on a `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/kstream/Transformer.html[Transformer]` and a `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/state/WindowStore.html[Window Store]` to filter out the duplicate IP addresses. Events are de-duped within a 2 minute window, and unique clicks are produced to a new topic named `distinct-clicks`. | ||
| Focusing on the `buildTopology` method, note how the Kafka Streams topology relies on a `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/kstream/ValueTransformerWithKey.html[ValueTransformerWithKey]` and a `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/state/WindowStore.html[Window Store]` to filter out the duplicate IP addresses. Events are de-duped within a 2 minute window, and unique clicks are produced to a new topic named `distinct-clicks`. | ||
|
|
||
| NOTE: Note that we are using `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/kstream/ValueTransformerWithKey.html[ValueTransformerWithKey]` here instead of `https://docs.confluent.io/current/streams/javadocs/org/apache/kafka/streams/kstream/Transformer.html[Transformer]` since we need keys to transform data, but there is no need to re-key the stream. |
There was a problem hiding this comment.
Unfortunately, call-outs don't render correctly at the moment. Can you remove the NOTE: text? Maybe you could do something like **_Note that we are using_** instead. We are working on adding support for call-outs.
There was a problem hiding this comment.
Oh I see! I got used to Asciidoctor in my own projects, that's why I'm using its features without thinking about render support :-)
| Runtime.getRuntime().addShutdownHook(new Thread("streams-shutdown-hook") { | ||
| @Override | ||
| public void run() { | ||
| streams.close(); |
There was a problem hiding this comment.
Suggestion - I know this is pre-existing code, but can we update close() to close(Duration.ofSeconds(5))
|
validated by going through the tutorial steps and running the test harness locally. |
|
Bill Bejeck (@bbejeck) done as you suggested, apparently I also forgot to commit |
Ack and will do. Thanks for the quick response. |
Bill Bejeck (bbejeck)
left a comment
There was a problem hiding this comment.
Ivan Ponomarev (@inponomarev) I tried running the tutorial locally and I ran into some issues.
| compile "org.apache.avro:avro:1.8.2" | ||
| implementation "org.slf4j:slf4j-simple:1.7.26" | ||
| implementation "org.apache.kafka:kafka-streams:2.3.0" | ||
| implementation "org.apache.kafka:kafka-streams:2.4.1" |
There was a problem hiding this comment.
With this change I get the following when trying to run the app at step 6
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/clients/admin/Admin
at org.apache.kafka.streams.KafkaStreams.<init>(KafkaStreams.java:557)
at io.confluent.developer.FindDistinctEvents.runRecipe(FindDistinctEvents.java:235)
at io.confluent.developer.FindDistinctEvents.main(FindDistinctEvents.java:225)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.clients.admin.Admin
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 3 more
Maybe just revert to 2.3.0 for now?
There was a problem hiding this comment.
Yes, no time to investigate it right now... reverted to 2.3.0.
|
Thanks Ivan Ponomarev (@inponomarev) for the contribution. I've verified the tutorial steps and ran the test harness locally. I'm going to see about running the build for the PR before merging, but it will get merged soon regardless. Thanks again! |
Hello,
the current version of the tutorial uses
Transformer. However, sinceTransformermay change the key, its usage will lead to redundant repartitioning when grouping operations are used aftewards.I propose to rewrite this example using
ValueTransformer[WithKey], which will not cause the unwanted repartitioning.By the way, it seems to me that we have a bug in
transformValues: see thefilter((k, v) -> v != null)after it. Without this filter,nullvalues appear downstream, contrary to what is said in JavaDoc: