Search in sources :

Example 1 with AddToCart

use of datamodel.AddToCart in project hazelcast-jet-reference-manual by hazelcast.

the class ImplementAggregation method s2.

static void s2() {
    // tag::s2[]
    Pipeline p = Pipeline.create();
    BatchStage<PageVisit> pageVisit = p.drawFrom(Sources.list("pageVisit"));
    BatchStage<AddToCart> addToCart = p.drawFrom(Sources.list("addToCart"));
    BatchStage<Payment> payment = p.drawFrom(Sources.list("payment"));
    AggregateOperation3<PageVisit, AddToCart, Payment, LongAccumulator[], long[]> aggrOp = AggregateOperation.withCreate(() -> new LongAccumulator[] { new LongAccumulator(), new LongAccumulator(), new LongAccumulator() }).<PageVisit>andAccumulate0((accs, pv) -> accs[0].add(pv.loadTime())).<AddToCart>andAccumulate1((accs, atc) -> accs[1].add(atc.quantity())).<Payment>andAccumulate2((accs, pm) -> accs[2].add(pm.amount())).andCombine((accs1, accs2) -> {
        accs1[0].add(accs2[0]);
        accs1[1].add(accs2[1]);
        accs1[2].add(accs2[2]);
    }).andFinish(accs -> new long[] { accs[0].get(), accs[1].get(), accs[2].get() });
    BatchStage<Entry<Integer, long[]>> coGrouped = pageVisit.groupingKey(PageVisit::userId).aggregate3(addToCart.groupingKey(AddToCart::userId), payment.groupingKey(Payment::userId), aggrOp);
// end::s2[]
}
Also used : LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) PageVisit(datamodel.PageVisit) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Pipeline(com.hazelcast.jet.pipeline.Pipeline) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Entry(java.util.Map.Entry) AggregateOperation3(com.hazelcast.jet.aggregate.AggregateOperation3) Payment(datamodel.Payment) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) AddToCart(datamodel.AddToCart) PageVisit(datamodel.PageVisit) Payment(datamodel.Payment) Entry(java.util.Map.Entry) AddToCart(datamodel.AddToCart) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 2 with AddToCart

use of datamodel.AddToCart in project hazelcast-jet-reference-manual by hazelcast.

the class BuildComputation method s9.

// end::s8[]
static void s9() {
    // tag::s9[]
    Pipeline p = Pipeline.create();
    // Create three source streams
    StageWithGrouping<PageVisit, Integer> pageVisits = p.drawFrom(Sources.<PageVisit>list("pageVisit")).groupingKey(PageVisit::userId);
    StageWithGrouping<AddToCart, Integer> addToCarts = p.drawFrom(Sources.<AddToCart>list("addToCart")).groupingKey(AddToCart::userId);
    StageWithGrouping<Payment, Integer> payments = p.drawFrom(Sources.<Payment>list("payment")).groupingKey(Payment::userId);
    StageWithGrouping<Delivery, Integer> deliveries = p.drawFrom(Sources.<Delivery>list("delivery")).groupingKey(Delivery::userId);
    // Obtain a builder object for the co-group transform
    GroupAggregateBuilder<PageVisit, Integer> builder = pageVisits.aggregateBuilder();
    Tag<PageVisit> visitTag = builder.tag0();
    // Add the co-grouped streams to the builder.
    Tag<AddToCart> cartTag = builder.add(addToCarts);
    Tag<Payment> payTag = builder.add(payments);
    Tag<Delivery> deliveryTag = builder.add(deliveries);
    // Build the co-group transform. The aggregate operation collects all
    // the stream items inside an accumulator class called BagsByTag.
    BatchStage<Entry<Integer, BagsByTag>> coGrouped = builder.build(toBagsByTag(visitTag, cartTag, payTag, deliveryTag));
// end::s9[]
}
Also used : PageVisit(datamodel.PageVisit) AddToCart(datamodel.AddToCart) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Payment(datamodel.Payment) Entry(java.util.Map.Entry) Delivery(datamodel.Delivery)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)2 AddToCart (datamodel.AddToCart)2 PageVisit (datamodel.PageVisit)2 Payment (datamodel.Payment)2 Entry (java.util.Map.Entry)2 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)1 LongLongAccumulator (com.hazelcast.jet.accumulator.LongLongAccumulator)1 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)1 AggregateOperation1 (com.hazelcast.jet.aggregate.AggregateOperation1)1 AggregateOperation3 (com.hazelcast.jet.aggregate.AggregateOperation3)1 BatchStage (com.hazelcast.jet.pipeline.BatchStage)1 Sources (com.hazelcast.jet.pipeline.Sources)1 Delivery (datamodel.Delivery)1