Search in sources :

Example 11 with Bid

use of org.apache.beam.sdk.nexmark.model.Bid in project beam by apache.

the class Query2 method expand.

@Override
public PCollection<AuctionPrice> expand(PCollection<Event> events) {
    return events.apply(NexmarkQueryUtil.JUST_BIDS).apply(Filter.by(bid -> bid.auction % this.auctionSkip == 0)).apply(name + ".Project", ParDo.of(new DoFn<Bid, AuctionPrice>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
            Bid bid = c.element();
            c.output(new AuctionPrice(bid.auction, bid.price));
        }
    }));
}
Also used : DoFn(org.apache.beam.sdk.transforms.DoFn) Bid(org.apache.beam.sdk.nexmark.model.Bid) AuctionPrice(org.apache.beam.sdk.nexmark.model.AuctionPrice)

Example 12 with Bid

use of org.apache.beam.sdk.nexmark.model.Bid 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()));
        }
    }));
}
Also used : Auction(org.apache.beam.sdk.nexmark.model.Auction) KV(org.apache.beam.sdk.values.KV) DoFn(org.apache.beam.sdk.transforms.DoFn) AuctionBid(org.apache.beam.sdk.nexmark.model.AuctionBid) CategoryPrice(org.apache.beam.sdk.nexmark.model.CategoryPrice) Bid(org.apache.beam.sdk.nexmark.model.Bid) AuctionBid(org.apache.beam.sdk.nexmark.model.AuctionBid)

Aggregations

Bid (org.apache.beam.sdk.nexmark.model.Bid)12 AuctionBid (org.apache.beam.sdk.nexmark.model.AuctionBid)5 DoFn (org.apache.beam.sdk.transforms.DoFn)5 KV (org.apache.beam.sdk.values.KV)5 Auction (org.apache.beam.sdk.nexmark.model.Auction)4 NexmarkConfiguration (org.apache.beam.sdk.nexmark.NexmarkConfiguration)3 Event (org.apache.beam.sdk.nexmark.model.Event)3 PCollection (org.apache.beam.sdk.values.PCollection)3 TimestampedValue (org.apache.beam.sdk.values.TimestampedValue)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 Instant (org.joda.time.Instant)2 Test (org.junit.Test)2 Category (org.junit.experimental.categories.Category)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 SqlTransform (org.apache.beam.sdk.extensions.sql.SqlTransform)1 CalciteQueryPlanner (org.apache.beam.sdk.extensions.sql.impl.CalciteQueryPlanner)1 QueryPlanner (org.apache.beam.sdk.extensions.sql.impl.QueryPlanner)1