Search in sources :

Example 1 with Broker

use of datamodel.Broker in project hazelcast-jet-reference-manual by hazelcast.

the class BuildComputation method s11.

static void s11() {
    // tag::s11[]
    Pipeline p = Pipeline.create();
    // The stream to be enriched: trades
    StreamStage<Trade> trades = p.drawFrom(Sources.mapJournal("trades", mapPutEvents(), mapEventNewValue(), START_FROM_CURRENT));
    // The enriching streams: products, brokers and markets
    BatchStage<Entry<Integer, Product>> prodEntries = p.drawFrom(Sources.map("products"));
    BatchStage<Entry<Integer, Broker>> brokEntries = p.drawFrom(Sources.map("brokers"));
    BatchStage<Entry<Integer, Market>> marketEntries = p.drawFrom(Sources.map("markets"));
    // Obtain a hash-join builder object from the stream to be enriched
    StreamHashJoinBuilder<Trade> builder = trades.hashJoinBuilder();
    // Add enriching streams to the builder
    Tag<Product> productTag = builder.add(prodEntries, joinMapEntries(Trade::productId));
    Tag<Broker> brokerTag = builder.add(brokEntries, joinMapEntries(Trade::brokerId));
    Tag<Market> marketTag = builder.add(marketEntries, joinMapEntries(Trade::marketId));
    // Build the hash join pipeline
    StreamStage<Tuple2<Trade, ItemsByTag>> joined = builder.build(Tuple2::tuple2);
    // end::s11[]
    // tag::s12[]
    StreamStage<String> mapped = joined.map((Tuple2<Trade, ItemsByTag> tuple) -> {
        Trade trade = tuple.f0();
        ItemsByTag ibt = tuple.f1();
        Product product = ibt.get(productTag);
        Broker broker = ibt.get(brokerTag);
        Market market = ibt.get(marketTag);
        return trade + ": " + product + ", " + broker + ", " + market;
    });
// end::s12[]
}
Also used : Broker(datamodel.Broker) Product(datamodel.Product) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Market(datamodel.Market) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Trade(datamodel.Trade) Entry(java.util.Map.Entry) Tuple2(com.hazelcast.jet.datamodel.Tuple2)

Aggregations

ItemsByTag (com.hazelcast.jet.datamodel.ItemsByTag)1 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)1 Pipeline (com.hazelcast.jet.pipeline.Pipeline)1 Broker (datamodel.Broker)1 Market (datamodel.Market)1 Product (datamodel.Product)1 Trade (datamodel.Trade)1 Entry (java.util.Map.Entry)1