0
0
Kafkadevops~10 mins

Filter and map operations in Kafka - Interactive Code Practice

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

Complete the code to filter messages with value greater than 10.

Kafka
stream.filter(record -> record.value() [1] 10);
Drag options to blanks, or click blank then click option'
A>
B<=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will filter the wrong records.
Using '==' will only keep records equal to 10.
2fill in blank
medium

Complete the code to map each record to its key.

Kafka
stream.map(record -> record.[1]());
Drag options to blanks, or click blank then click option'
Avalue
Btopic
Ctimestamp
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using value() returns the value, not the key.
Using timestamp() or topic() returns other info.
3fill in blank
hard

Fix the error in the filter condition to keep records with even values.

Kafka
stream.filter(record -> record.value() [1] 2 == 0);
Drag options to blanks, or click blank then click option'
A/
B*
C%
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using division / instead of modulo %.
Using multiplication or addition operators.
4fill in blank
hard

Fill both blanks to create a map of keys to values for records with values greater than 5.

Kafka
stream.filter(record -> record.value() [1] 5).map(record -> new KeyValue<>(record.[2](), record.value()));
Drag options to blanks, or click blank then click option'
A>
B<
Ckey
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter.
Using value() instead of key() for the key.
5fill in blank
hard

Fill all three blanks to filter records with values less than 20, map to uppercase keys, and keep values.

Kafka
stream.filter(record -> record.value() [1] 20).map(record -> new KeyValue<>(record.[2]().[3](), record.value()));
Drag options to blanks, or click blank then click option'
A<
Bvalue
CtoUpperCase
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in the filter.
Using value() instead of key() for the key.
Not calling toUpperCase() on the key.