Bird
Raised Fist0
Kafkadevops~10 mins

Why stream processing transforms data in Kafka - Test Your Understanding

Choose your learning style10 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

Practice

(1/5)
1. Why do we use stream processing to transform data in Kafka Streams?
easy
A. To make data more useful and meaningful in real time
B. To store data permanently without changes
C. To slow down data flow for analysis later
D. To delete unnecessary data immediately

Solution

  1. Step 1: Understand the purpose of stream processing

    Stream processing changes data as it flows to add value or meaning instantly.
  2. Step 2: Identify the correct purpose from options

    Only To make data more useful and meaningful in real time says it makes data more useful in real time, which matches the purpose.
  3. Final Answer:

    To make data more useful and meaningful in real time -> Option A
  4. Quick Check:

    Stream processing transforms data = Make data useful [OK]
Hint: Stream processing changes data to add value instantly [OK]
Common Mistakes:
  • Thinking stream processing only stores data
  • Believing it slows down data flow
  • Confusing transformation with deletion
2. Which of the following is the correct way to apply a map transformation in Kafka Streams using Java?
easy
A. stream.reduce((v1, v2) -> v1 + v2)
B. stream.filter(value -> value.length())
C. stream.mapValues(value -> value.toUpperCase())
D. stream.collect(Collectors.toList())

Solution

  1. Step 1: Identify the map transformation syntax

    In Kafka Streams, mapValues applies a function to each value, e.g., converting to uppercase.
  2. Step 2: Match the correct syntax

    stream.mapValues(value -> value.toUpperCase()) uses mapValues with a lambda toUpperCase(), which is correct.
  3. Final Answer:

    stream.mapValues(value -> value.toUpperCase()) -> Option C
  4. Quick Check:

    map transformation syntax = mapValues with lambda [OK]
Hint: Map uses mapValues with a function on values [OK]
Common Mistakes:
  • Using filter instead of map
  • Using reduce for mapping
  • Using collect which is not a stream operation here
3. Given the following Kafka Streams code snippet, what will be the output if the input stream has values ["apple", "banana", "cherry"]?
stream.filter((k, v) -> v.startsWith("b")).toList()
medium
A. ["banana"]
B. ["apple", "banana", "cherry"]
C. ["cherry"]
D. []

Solution

  1. Step 1: Understand the filter condition

    The filter keeps only values starting with 'b'. From the list, only "banana" starts with 'b'.
  2. Step 2: Determine the output list

    After filtering, the list contains only ["banana"].
  3. Final Answer:

    ["banana"] -> Option A
  4. Quick Check:

    Filter by startsWith('b') = ["banana"] [OK]
Hint: Filter keeps only matching values [OK]
Common Mistakes:
  • Including all values without filtering
  • Choosing values starting with wrong letters
  • Confusing filter with map
4. Identify the error in this Kafka Streams code snippet that tries to filter out empty strings:
stream.filter((k, v) -> v != "")
medium
A. filter() cannot be used on streams
B. Missing semicolon at the end
C. Lambda syntax is incorrect
D. Using '!=' to compare strings instead of .equals()

Solution

  1. Step 1: Check string comparison in Java

    In Java, '!=' compares object references, not string content. Use .equals() to compare strings.
  2. Step 2: Identify the correct fix

    Replace 'value != ""' with '!value.equals("")' to properly filter out empty strings.
  3. Final Answer:

    Using '!=' to compare strings instead of .equals() -> Option D
  4. Quick Check:

    String comparison needs .equals() [OK]
Hint: Use .equals() to compare strings in Java [OK]
Common Mistakes:
  • Using '==' or '!=' for string content comparison
  • Assuming filter() is invalid on streams
  • Ignoring lambda syntax correctness
5. You want to enrich a Kafka stream of user IDs by adding their names from a lookup table. Which approach best uses stream processing transformations?
hard
A. Reduce the stream to count user IDs
B. Use a join operation between the user ID stream and the user info table
C. Map the stream values to uppercase user IDs
D. Filter the stream to only user IDs present in the table

Solution

  1. Step 1: Understand enrichment in stream processing

    Enrichment means adding extra data, here user names, to existing stream data.
  2. Step 2: Identify the correct transformation

    Joining the user ID stream with the user info table adds the names, which is enrichment.
  3. Final Answer:

    Use a join operation between the user ID stream and the user info table -> Option B
  4. Quick Check:

    Enrich data = join streams/tables [OK]
Hint: Enrich data by joining streams with lookup tables [OK]
Common Mistakes:
  • Using filter which only removes data
  • Mapping to uppercase does not add info
  • Reducing counts data, not enriches
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard