Search in sources :

Example 1 with SelectEvent

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

the class SqlBoundedSideInputJoin method expand.

@Override
public PCollection<Bid> expand(PCollection<Event> events) {
    PCollection<Row> bids = events.apply(Filter.by(NexmarkQueryUtil.IS_BID)).apply(getName() + ".SelectEvent", new SelectEvent(Event.Type.BID));
    checkState(getSideInput() != null, "Configuration error: side input is null");
    TupleTag<Row> sideTag = new TupleTag<Row>("side") {
    };
    TupleTag<Row> bidTag = new TupleTag<Row>("bid") {
    };
    Schema schema = Schema.of(Schema.Field.of("id", Schema.FieldType.INT64), Schema.Field.of("extra", Schema.FieldType.STRING));
    PCollection<Row> sideRows = getSideInput().setSchema(schema, TypeDescriptors.kvs(TypeDescriptors.longs(), TypeDescriptors.strings()), kv -> Row.withSchema(schema).addValues(kv.getKey(), kv.getValue()).build(), row -> KV.of(row.getInt64("id"), row.getString("extra"))).apply("SideToRows", Convert.toRows());
    return PCollectionTuple.of(bidTag, bids).and(sideTag, sideRows).apply(SqlTransform.query(String.format(query, configuration.sideInputRowCount)).withQueryPlannerClass(plannerClass)).apply("ResultToBid", Convert.fromRows(Bid.class));
}
Also used : NexmarkConfiguration(org.apache.beam.sdk.nexmark.NexmarkConfiguration) KV(org.apache.beam.sdk.values.KV) QueryPlanner(org.apache.beam.sdk.extensions.sql.impl.QueryPlanner) ZetaSQLQueryPlanner(org.apache.beam.sdk.extensions.sql.zetasql.ZetaSQLQueryPlanner) Bid(org.apache.beam.sdk.nexmark.model.Bid) SelectEvent(org.apache.beam.sdk.nexmark.model.sql.SelectEvent) PCollection(org.apache.beam.sdk.values.PCollection) SqlTransform(org.apache.beam.sdk.extensions.sql.SqlTransform) Schema(org.apache.beam.sdk.schemas.Schema) Convert(org.apache.beam.sdk.schemas.transforms.Convert) Filter(org.apache.beam.sdk.transforms.Filter) CalciteQueryPlanner(org.apache.beam.sdk.extensions.sql.impl.CalciteQueryPlanner) Event(org.apache.beam.sdk.nexmark.model.Event) Preconditions.checkState(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState) TupleTag(org.apache.beam.sdk.values.TupleTag) TypeDescriptors(org.apache.beam.sdk.values.TypeDescriptors) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) NexmarkQueryTransform(org.apache.beam.sdk.nexmark.queries.NexmarkQueryTransform) NexmarkQueryUtil(org.apache.beam.sdk.nexmark.queries.NexmarkQueryUtil) Row(org.apache.beam.sdk.values.Row) Schema(org.apache.beam.sdk.schemas.Schema) TupleTag(org.apache.beam.sdk.values.TupleTag) Row(org.apache.beam.sdk.values.Row) Bid(org.apache.beam.sdk.nexmark.model.Bid) SelectEvent(org.apache.beam.sdk.nexmark.model.sql.SelectEvent)

Example 2 with SelectEvent

use of org.apache.beam.sdk.nexmark.model.sql.SelectEvent 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 SelectEvent (org.apache.beam.sdk.nexmark.model.sql.SelectEvent)2 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)2 Row (org.apache.beam.sdk.values.Row)2 TupleTag (org.apache.beam.sdk.values.TupleTag)2 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 ZetaSQLQueryPlanner (org.apache.beam.sdk.extensions.sql.zetasql.ZetaSQLQueryPlanner)1 NexmarkConfiguration (org.apache.beam.sdk.nexmark.NexmarkConfiguration)1 Bid (org.apache.beam.sdk.nexmark.model.Bid)1 NameCityStateId (org.apache.beam.sdk.nexmark.model.NameCityStateId)1 NexmarkQueryTransform (org.apache.beam.sdk.nexmark.queries.NexmarkQueryTransform)1 NexmarkQueryUtil (org.apache.beam.sdk.nexmark.queries.NexmarkQueryUtil)1 Schema (org.apache.beam.sdk.schemas.Schema)1 Convert (org.apache.beam.sdk.schemas.transforms.Convert)1 Filter (org.apache.beam.sdk.transforms.Filter)1 KV (org.apache.beam.sdk.values.KV)1 PCollection (org.apache.beam.sdk.values.PCollection)1 TypeDescriptors (org.apache.beam.sdk.values.TypeDescriptors)1