@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236 private static Pipeline coGroupBuild() { Pipeline p = Pipeline.create(); // Create three source streams BatchStageWithKey<PageVisit, Integer> pageVisits = p.drawFrom(Sources.<PageVisit>list(PAGE_VISIT)) .groupingKey(pageVisit -> pageVisit.userId()); BatchStageWithKey<AddToCart, Integer> addToCarts = p.drawFrom(Sources.<AddToCart>list(ADD_TO_CART)) .groupingKey(addToCart -> addToCart.userId()); BatchStageWithKey<Payment, Integer> payments = p.drawFrom(Sources.<Payment>list(PAYMENT)) .groupingKey(payment -> payment.userId()); // Obtain a builder object for the co-group transform GroupAggregateBuilder<Integer, List<PageVisit>> builder = pageVisits.aggregateBuilder(toList()); Tag<List<PageVisit>> visitTag = builder.tag0(); // Add the co-grouped streams to the builder. Here we add just two, but // you could add any number of them. Tag<List<AddToCart>> cartTag = builder.add(addToCarts, toList()); Tag<List<Payment>> payTag = builder.add(payments, toList()); // Build the co-group transform. The aggregate operation collects all the // stream items into an accumulator class called ItemsByTag. We transform // it into a 3-tuple of lists. BatchStage<Entry<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>>> coGrouped = builder.build((key, res) -> entry(key, tuple3(res.get(visitTag), res.get(cartTag), res.get(payTag)))); // Store the results in the output map coGrouped.drainTo(Sinks.map(RESULT)); return p; }
@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236 private static Pipeline coGroupBuild() { Pipeline p = Pipeline.create(); // Create three source streams BatchStageWithKey<PageVisit, Integer> pageVisits = p.drawFrom(Sources.<PageVisit>list(PAGE_VISIT)) .groupingKey(pageVisit -> pageVisit.userId()); BatchStageWithKey<AddToCart, Integer> addToCarts = p.drawFrom(Sources.<AddToCart>list(ADD_TO_CART)) .groupingKey(addToCart -> addToCart.userId()); BatchStageWithKey<Payment, Integer> payments = p.drawFrom(Sources.<Payment>list(PAYMENT)) .groupingKey(payment -> payment.userId()); // Obtain a builder object for the co-group transform GroupAggregateBuilder<Integer, List<PageVisit>> builder = pageVisits.aggregateBuilder(toList()); Tag<List<PageVisit>> visitTag = builder.tag0(); // Add the co-grouped streams to the builder. Here we add just two, but // you could add any number of them. Tag<List<AddToCart>> cartTag = builder.add(addToCarts, toList()); Tag<List<Payment>> payTag = builder.add(payments, toList()); // Build the co-group transform. The aggregate operation collects all the // stream items into an accumulator class called ItemsByTag. We transform // it into a 3-tuple of lists. BatchStage<Entry<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>>> coGrouped = builder.build((key, res) -> entry(key, tuple3(res.get(visitTag), res.get(cartTag), res.get(payTag)))); // Store the results in the output map coGrouped.drainTo(Sinks.map(RESULT)); return p; }