use of org.apache.beam.sdk.nexmark.model.NameCityStateId in project beam by apache.
the class Query3 method expand.
@Override
public PCollection<NameCityStateId> expand(PCollection<Event> events) {
PCollection<KV<Long, Event>> auctionsBySellerId = events.apply(NexmarkQueryUtil.JUST_NEW_AUCTIONS).apply(name + ".InCategory", Filter.by(auction -> auction.category == 10)).apply("EventByAuctionSeller", ParDo.of(new DoFn<Auction, KV<Long, Event>>() {
@ProcessElement
public void processElement(ProcessContext c) {
Event e = new Event();
e.newAuction = c.element();
c.output(KV.of(c.element().seller, e));
}
}));
PCollection<KV<Long, Event>> personsById = events.apply(NexmarkQueryUtil.JUST_NEW_PERSONS).apply(name + ".InState", Filter.by(person -> "OR".equals(person.state) || "ID".equals(person.state) || "CA".equals(person.state))).apply("EventByPersonId", ParDo.of(new DoFn<Person, KV<Long, Event>>() {
@ProcessElement
public void processElement(ProcessContext c) {
Event e = new Event();
e.newPerson = c.element();
c.output(KV.of(c.element().id, e));
}
}));
// Join auctions and people.
return PCollectionList.of(auctionsBySellerId).and(personsById).apply(Flatten.pCollections()).apply(name + ".Join", ParDo.of(joinDoFn)).apply(name + ".Project", ParDo.of(new DoFn<KV<Auction, Person>, NameCityStateId>() {
@ProcessElement
public void processElement(ProcessContext c) {
Auction auction = c.element().getKey();
Person person = c.element().getValue();
c.output(new NameCityStateId(person.name, person.city, person.state, auction.id));
}
}));
}
use of org.apache.beam.sdk.nexmark.model.NameCityStateId in project beam by apache.
the class SqlQuery3 method expand.
@Override
public PCollection<NameCityStateId> expand(PCollection<Event> allEvents) {
PCollection<Event> windowed = allEvents.apply(Window.into(FixedWindows.of(Duration.standardSeconds(configuration.windowSizeSec))));
String auctionName = Auction.class.getSimpleName();
PCollection<Row> auctions = windowed.apply(getName() + ".Filter." + auctionName, Filter.by(e1 -> e1.newAuction != null)).apply(getName() + ".ToRecords." + auctionName, new SelectEvent(Event.Type.AUCTION));
String personName = Person.class.getSimpleName();
PCollection<Row> people = windowed.apply(getName() + ".Filter." + personName, Filter.by(e -> e.newPerson != null)).apply(getName() + ".ToRecords." + personName, new SelectEvent(Event.Type.PERSON));
PCollectionTuple inputStreams = PCollectionTuple.of(new TupleTag<>("Auction"), auctions).and(new TupleTag<>("Person"), people);
return inputStreams.apply(SqlTransform.query(QUERY).withQueryPlannerClass(plannerClass)).apply(Convert.fromRows(NameCityStateId.class));
}
Aggregations