use of org.apache.beam.sdk.nexmark.model.Bid in project beam by apache.
the class Query2 method expand.
@Override
public PCollection<AuctionPrice> expand(PCollection<Event> events) {
return events.apply(NexmarkQueryUtil.JUST_BIDS).apply(Filter.by(bid -> bid.auction % this.auctionSkip == 0)).apply(name + ".Project", ParDo.of(new DoFn<Bid, AuctionPrice>() {
@ProcessElement
public void processElement(ProcessContext c) {
Bid bid = c.element();
c.output(new AuctionPrice(bid.auction, bid.price));
}
}));
}
use of org.apache.beam.sdk.nexmark.model.Bid in project beam by apache.
the class Query4 method expand.
@Override
public PCollection<CategoryPrice> expand(PCollection<Event> events) {
PCollection<AuctionBid> winningBids = events.apply(Filter.by(new AuctionOrBid())).apply(new WinningBids(name + ".WinningBids", configuration));
// Monitor winning bids
winningBids = winningBids.apply(name + ".WinningBidsMonitor", winningBidsMonitor.getTransform());
return winningBids.apply(name + ".Rekey", ParDo.of(new DoFn<AuctionBid, KV<Long, Long>>() {
@ProcessElement
public void processElement(ProcessContext c) {
Auction auction = c.element().auction;
Bid bid = c.element().bid;
c.output(KV.of(auction.category, bid.price));
}
})).apply(Window.into(SlidingWindows.of(Duration.standardSeconds(configuration.windowSizeSec)).every(Duration.standardSeconds(configuration.windowPeriodSec)))).apply(Mean.<Long, Long>perKey().withHotKeyFanout(configuration.fanout)).apply(name + ".Project", ParDo.of(new DoFn<KV<Long, Double>, CategoryPrice>() {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(new CategoryPrice(c.element().getKey(), Math.round(c.element().getValue()), c.pane().isLast()));
}
}));
}
Aggregations