Search in sources :

Example 1 with SingleJoinBolt

use of org.apache.storm.starter.bolt.SingleJoinBolt in project storm by apache.

the class SingleJoinExample method main.

public static void main(String[] args) throws Exception {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("gender", genderSpout);
    builder.setSpout("age", ageSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
    Config conf = new Config();
    conf.setDebug(true);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology("join-example", conf, builder.createTopology())) {
        for (int i = 0; i < 10; i++) {
            String gender;
            if (i % 2 == 0) {
                gender = "male";
            } else {
                gender = "female";
            }
            genderSpout.feed(new Values(i, gender));
        }
        for (int i = 9; i >= 0; i--) {
            ageSpout.feed(new Values(i, i + 20));
        }
        Utils.sleep(2000);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) SingleJoinBolt(org.apache.storm.starter.bolt.SingleJoinBolt) Values(org.apache.storm.tuple.Values) FeederSpout(org.apache.storm.testing.FeederSpout) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 2 with SingleJoinBolt

use of org.apache.storm.starter.bolt.SingleJoinBolt in project flink by apache.

the class SingleJoinExample method main.

public static void main(String[] args) throws Exception {
    final FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender", "hobbies"));
    final FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    Config conf = new Config();
    TopologyBuilder builder = new TopologyBuilder();
    //  only required to stabilize integration test
    conf.put(FlinkLocalCluster.SUBMIT_BLOCKING, true);
    final NullTerminatingSpout finalGenderSpout = new NullTerminatingSpout(genderSpout);
    final NullTerminatingSpout finalAgeSpout = new NullTerminatingSpout(ageSpout);
    builder.setSpout("gender", finalGenderSpout);
    builder.setSpout("age", finalAgeSpout);
    builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
    // emit result
    if (args.length > 0) {
        // read the text file from given input path
        builder.setBolt("fileOutput", new BoltFileSink(args[0], new TupleOutputFormatter())).shuffleGrouping("join");
    } else {
        builder.setBolt("print", new PrinterBolt()).shuffleGrouping("join");
    }
    String[] hobbies = new String[] { "reading", "biking", "travelling", "watching tv" };
    for (int i = 0; i < 10; i++) {
        String gender;
        if (i % 2 == 0) {
            gender = "male";
        } else {
            gender = "female";
        }
        genderSpout.feed(new Values(i, gender, hobbies[i % hobbies.length]));
    }
    for (int i = 9; i >= 0; i--) {
        ageSpout.feed(new Values(i, i + 20));
    }
    final FlinkLocalCluster cluster = FlinkLocalCluster.getLocalCluster();
    cluster.submitTopology("joinTopology", conf, FlinkTopology.createTopology(builder));
    cluster.shutdown();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) TupleOutputFormatter(org.apache.flink.storm.util.TupleOutputFormatter) Values(org.apache.storm.tuple.Values) NullTerminatingSpout(org.apache.flink.storm.util.NullTerminatingSpout) BoltFileSink(org.apache.flink.storm.util.BoltFileSink) Fields(org.apache.storm.tuple.Fields) FlinkLocalCluster(org.apache.flink.storm.api.FlinkLocalCluster) SingleJoinBolt(org.apache.storm.starter.bolt.SingleJoinBolt) FeederSpout(org.apache.storm.testing.FeederSpout) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt)

Aggregations

Config (org.apache.storm.Config)2 SingleJoinBolt (org.apache.storm.starter.bolt.SingleJoinBolt)2 FeederSpout (org.apache.storm.testing.FeederSpout)2 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)2 Fields (org.apache.storm.tuple.Fields)2 Values (org.apache.storm.tuple.Values)2 FlinkLocalCluster (org.apache.flink.storm.api.FlinkLocalCluster)1 BoltFileSink (org.apache.flink.storm.util.BoltFileSink)1 NullTerminatingSpout (org.apache.flink.storm.util.NullTerminatingSpout)1 TupleOutputFormatter (org.apache.flink.storm.util.TupleOutputFormatter)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)1 PrinterBolt (org.apache.storm.starter.bolt.PrinterBolt)1