Search in sources :

Example 1 with NameCityStateId

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));
        }
    }));
}
Also used : DoFn(org.apache.beam.sdk.transforms.DoFn) NameCityStateId(org.apache.beam.sdk.nexmark.model.NameCityStateId) Auction(org.apache.beam.sdk.nexmark.model.Auction) Event(org.apache.beam.sdk.nexmark.model.Event) KV(org.apache.beam.sdk.values.KV) Person(org.apache.beam.sdk.nexmark.model.Person)

Example 2 with NameCityStateId

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));
}
Also used : NameCityStateId(org.apache.beam.sdk.nexmark.model.NameCityStateId) SelectEvent(org.apache.beam.sdk.nexmark.model.sql.SelectEvent) Event(org.apache.beam.sdk.nexmark.model.Event) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) TupleTag(org.apache.beam.sdk.values.TupleTag) Row(org.apache.beam.sdk.values.Row) SelectEvent(org.apache.beam.sdk.nexmark.model.sql.SelectEvent)

Aggregations

Event (org.apache.beam.sdk.nexmark.model.Event)2 NameCityStateId (org.apache.beam.sdk.nexmark.model.NameCityStateId)2 Auction (org.apache.beam.sdk.nexmark.model.Auction)1 Person (org.apache.beam.sdk.nexmark.model.Person)1 SelectEvent (org.apache.beam.sdk.nexmark.model.sql.SelectEvent)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 KV (org.apache.beam.sdk.values.KV)1 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)1 Row (org.apache.beam.sdk.values.Row)1 TupleTag (org.apache.beam.sdk.values.TupleTag)1