use of org.apache.beam.sdk.nexmark.model.Auction 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()));
}
}));
}
use of org.apache.beam.sdk.nexmark.model.Auction in project beam by apache.
the class Query8 method expand.
@Override
public PCollection<IdNameReserve> expand(PCollection<Event> events) {
// Window and key new people by their id.
PCollection<KV<Long, Person>> personsById = events.apply(NexmarkQueryUtil.JUST_NEW_PERSONS).apply("Query8.WindowPersons", Window.into(FixedWindows.of(Duration.standardSeconds(configuration.windowSizeSec)))).apply("PersonById", NexmarkQueryUtil.PERSON_BY_ID);
// Window and key new auctions by their id.
PCollection<KV<Long, Auction>> auctionsBySeller = events.apply(NexmarkQueryUtil.JUST_NEW_AUCTIONS).apply("Query8.WindowAuctions", Window.into(FixedWindows.of(Duration.standardSeconds(configuration.windowSizeSec)))).apply("AuctionBySeller", NexmarkQueryUtil.AUCTION_BY_SELLER);
// Join people and auctions and project the person id, name and auction reserve price.
return KeyedPCollectionTuple.of(NexmarkQueryUtil.PERSON_TAG, personsById).and(NexmarkQueryUtil.AUCTION_TAG, auctionsBySeller).apply(CoGroupByKey.create()).apply(name + ".Select", ParDo.of(new DoFn<KV<Long, CoGbkResult>, IdNameReserve>() {
@ProcessElement
public void processElement(ProcessContext c) {
@Nullable Person person = c.element().getValue().getOnly(NexmarkQueryUtil.PERSON_TAG, null);
if (person == null) {
// Person was not created in last window period.
return;
}
for (Auction auction : c.element().getValue().getAll(NexmarkQueryUtil.AUCTION_TAG)) {
c.output(new IdNameReserve(person.id, person.name, auction.reserve));
}
}
}));
}
Aggregations