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));
}
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));
}
Aggregations