0
0
Kafkadevops~10 mins

Why stream processing transforms data in Kafka - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to transform each message value to uppercase in a Kafka Streams application.

Kafka
KStream<String, String> stream = builder.stream("input-topic");
KStream<String, String> transformed = stream.mapValues(value -> value.[1]());
Drag options to blanks, or click blank then click option'
AtoLowerCase
BtoUpperCase
Ctrim
Dsubstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using toLowerCase() instead of toUpperCase()
Forgetting parentheses after method name
2fill in blank
medium

Complete the code to filter messages where the value length is greater than 5.

Kafka
KStream<String, String> filtered = stream.filter((key, value) -> value.[1]() > 5);
Drag options to blanks, or click blank then click option'
Asize
BlengthOf
Clength
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using size() which is for collections, not strings
Using count() which is not a String method
3fill in blank
hard

Fix the error in the code to correctly convert the message value to an integer before doubling it.

Kafka
KStream<String, Integer> doubled = stream.mapValues(value -> Integer.[1](value) * 2);
Drag options to blanks, or click blank then click option'
AparseInt
BvalueOf
CtoInt
Dconvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using valueOf() which returns Integer object, not int
Using non-existent methods like toInt() or convert()
4fill in blank
hard

Fill both blanks to create a map of word counts from a stream of sentences.

Kafka
KTable<String, Long> wordCounts = stream
  .flatMapValues(value -> Arrays.asList(value.toLowerCase().split(" ")))
  .groupBy((key, word) -> word)
  .[1]()
  .[2]();
Drag options to blanks, or click blank then click option'
Acount
Breduce
Caggregate
DgroupByKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using reduce() or aggregate() without grouping by key
Swapping the order of count() and groupByKey()
5fill in blank
hard

Fill all three blanks to filter, transform, and write the stream to an output topic.

Kafka
stream
  .filter((key, value) -> value.[1]() > 10)
  .mapValues(value -> value.[2]())
  .to("[3]", Produced.with(Serdes.String(), Serdes.String()));
Drag options to blanks, or click blank then click option'
Alength
BtoUpperCase
Coutput-topic
DtoLowerCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using toLowerCase() instead of toUpperCase()
Using wrong topic name
Forgetting parentheses after method names