0
0
Kafkadevops~10 mins

GroupBy and aggregation 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 group the stream by the 'user' field.

Kafka
KGroupedStream<String, String> groupedStream = stream.[1]();
Drag options to blanks, or click blank then click option'
Amap
BflatMap
Cfilter
DgroupByKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of groupByKey
Using map which transforms records but does not group
Using flatMap which expands records instead of grouping
2fill in blank
medium

Complete the code to count the number of records per key.

Kafka
KTable<String, Long> counts = groupedStream.[1]();
Drag options to blanks, or click blank then click option'
Aaggregate
Breduce
Ccount
DmapValues
Attempts:
3 left
💡 Hint
Common Mistakes
Using reduce which combines values but does not count
Using aggregate which requires more parameters
Using mapValues which transforms values but does not count
3fill in blank
hard

Fix the error in the aggregation code by completing the missing method.

Kafka
KTable<String, Integer> aggregated = groupedStream.[1](() -> 0, (key, value, aggregate) -> aggregate + Integer.parseInt(value));
Drag options to blanks, or click blank then click option'
Aaggregate
Bmap
Creduce
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count which does not take initializer or aggregator
Using reduce which does not take initializer
Using map which transforms but does not aggregate
4fill in blank
hard

Fill both blanks to group the stream by 'category' and sum the values as integers.

Kafka
KTable<String, Integer> summed = stream.mapValues(Integer::parseInt).[1]( (key, value) -> key.split(":")[0] ).[2](Integer::sum);
Drag options to blanks, or click blank then click option'
AgroupBy
BmapValues
Creduce
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using mapValues instead of groupBy
Using count instead of reduce
Using reduce without grouping first
5fill in blank
hard

Fill the blanks to create a grouped stream by 'type', aggregate values starting at 0, and add parsed integers.

Kafka
KTable<String, Integer> result = stream.[1]( (key, value) -> value.split(",")[0] ).[2](() -> 0, (aggKey, newValue, aggValue) -> aggValue + Integer.parseInt(newValue));
Drag options to blanks, or click blank then click option'
AgroupBy
Baggregate
CmapValues
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count instead of aggregate
Using mapValues instead of aggregate
Not grouping before aggregating