Search in sources :

Example 1 with BidsPerSession

use of org.apache.beam.sdk.nexmark.model.BidsPerSession in project beam by apache.

the class Query11 method expand.

@Override
public PCollection<BidsPerSession> expand(PCollection<Event> events) {
    PCollection<Long> bidders = events.apply(NexmarkQueryUtil.JUST_BIDS).apply(name + ".Rekey", ParDo.of(new DoFn<Bid, Long>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
            Bid bid = c.element();
            c.output(bid.bidder);
        }
    }));
    PCollection<Long> biddersWindowed = bidders.apply(Window.<Long>into(Sessions.withGapDuration(Duration.standardSeconds(configuration.windowSizeSec))).triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(configuration.maxLogEvents))).discardingFiredPanes().withAllowedLateness(Duration.standardSeconds(configuration.occasionalDelaySec / 2)));
    return biddersWindowed.apply(Count.perElement()).apply(name + ".ToResult", ParDo.of(new DoFn<KV<Long, Long>, BidsPerSession>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
            c.output(new BidsPerSession(c.element().getKey(), c.element().getValue()));
        }
    }));
}
Also used : BidsPerSession(org.apache.beam.sdk.nexmark.model.BidsPerSession) DoFn(org.apache.beam.sdk.transforms.DoFn) Bid(org.apache.beam.sdk.nexmark.model.Bid)

Aggregations

Bid (org.apache.beam.sdk.nexmark.model.Bid)1 BidsPerSession (org.apache.beam.sdk.nexmark.model.BidsPerSession)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1