use of org.apache.beam.sdk.nexmark.model.CategoryPrice in project beam by apache.
the class Query4Model method relevantResults.
@Override
protected Iterable<TimestampedValue<CategoryPrice>> relevantResults(Iterable<TimestampedValue<CategoryPrice>> results) {
// Find the last (in processing time) reported average price for each category.
Map<Long, TimestampedValue<CategoryPrice>> finalAverages = new TreeMap<>();
for (TimestampedValue<CategoryPrice> obj : results) {
Assert.assertTrue("have CategoryPrice", obj.getValue() instanceof CategoryPrice);
CategoryPrice categoryPrice = (CategoryPrice) obj.getValue();
if (categoryPrice.isLast) {
finalAverages.put(categoryPrice.category, TimestampedValue.of(categoryPrice, obj.getTimestamp()));
}
}
return finalAverages.values();
}
use of org.apache.beam.sdk.nexmark.model.CategoryPrice 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