use of org.apache.beam.sdk.nexmark.model.Person 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.Person in project beam by apache.
the class PersonGenerator method nextPerson.
/**
* Generate and return a random person with next available id.
*/
public static Person nextPerson(long nextEventId, Random random, DateTime timestamp, GeneratorConfig config) {
long id = lastBase0PersonId(nextEventId) + GeneratorConfig.FIRST_PERSON_ID;
String name = nextPersonName(random);
String email = nextEmail(random);
String creditCard = nextCreditCard(random);
String city = nextUSCity(random);
String state = nextUSState(random);
int currentSize = 8 + name.length() + email.length() + creditCard.length() + city.length() + state.length();
String extra = nextExtra(random, currentSize, config.getAvgPersonByteSize());
return new Person(id, name, email, creditCard, city, state, timestamp.toInstant(), extra);
}
use of org.apache.beam.sdk.nexmark.model.Person 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