Java for data engineers · JVM-02
Collections and streams
- 3 h
- requires JVM-01
From your world. a GROUP BY / window aggregation you'd write in SQL, expressed as a typed stream pipeline
Prompt A. "You have a List<OrderEvent>. Explain how a stream pipeline computes total revenue
per currency for valid rows only. Your listener knows SQL GROUP BY. Name the stream op that plays
the role of each SQL clause (WHERE, GROUP BY, SUM). Say why nothing runs until the terminal
op."
Prompt B. "Explain why map.merge(k, 1, Integer::sum) is the right way to count per key. Say
what goes wrong with map.put(k, map.get(k) + 1)."
Rubric — a strong explanation hits these (5–7):
- Maps
filter→WHERE,map→SELECT,groupingBy→GROUP BY,summingDouble→SUM. - States that intermediate ops are lazy and only the terminal op executes the pipeline.
- Distinguishes
map(1→1) fromflatMap(1→many / UNNEST). - Uses method references (
Order::amount) and explains them as a short form of a lambda. - Explains the
mergecounting idiom. Explains whyput(get+1)throws an NPE on the first insert. - Mentions associativity for
reduceand parallel streams (ties back to FND). - (Bonus) Notes that
List.ofis immutable and that you can use a stream only once.