Search in sources :

Example 1 with HBaseProjectionCriteria

use of org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria in project storm by apache.

the class LookupWordCount method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    Map<String, Object> hbConf = new HashMap<String, Object>();
    if (args.length > 0) {
        hbConf.put("hbase.rootdir", args[0]);
    }
    config.put("hbase.conf", hbConf);
    WordSpout spout = new WordSpout();
    TotalWordCounter totalBolt = new TotalWordCounter();
    SimpleHBaseMapper mapper = new SimpleHBaseMapper().withRowKeyField("word");
    HBaseProjectionCriteria projectionCriteria = new HBaseProjectionCriteria();
    projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count"));
    WordCountValueMapper rowToTupleMapper = new WordCountValueMapper();
    HBaseLookupBolt hBaseLookupBolt = new HBaseLookupBolt("WordCount", mapper, rowToTupleMapper).withConfigKey("hbase.conf").withProjectionCriteria(projectionCriteria);
    //wordspout -> lookupbolt -> totalCountBolt
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(WORD_SPOUT, spout, 1);
    builder.setBolt(LOOKUP_BOLT, hBaseLookupBolt, 1).shuffleGrouping(WORD_SPOUT);
    builder.setBolt(TOTAL_COUNT_BOLT, totalBolt, 1).fieldsGrouping(LOOKUP_BOLT, new Fields("columnName"));
    if (args.length == 1) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("test", config, builder.createTopology())) {
            Thread.sleep(30000);
        }
        System.exit(0);
    } else if (args.length == 2) {
        StormSubmitter.submitTopology(args[1], config, builder.createTopology());
    } else {
        System.out.println("Usage: LookupWordCount <hbase.rootdir>");
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) HBaseProjectionCriteria(org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) HBaseLookupBolt(org.apache.storm.hbase.bolt.HBaseLookupBolt) Fields(org.apache.storm.tuple.Fields) SimpleHBaseMapper(org.apache.storm.hbase.bolt.mapper.SimpleHBaseMapper)

Example 2 with HBaseProjectionCriteria

use of org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria in project storm by apache.

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String hbaseRoot) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    TridentHBaseMapper tridentHBaseMapper = new SimpleTridentHBaseMapper().withColumnFamily("cf").withColumnFields(new Fields("word")).withCounterFields(new Fields("count")).withRowKeyField("word");
    HBaseValueMapper rowToStormValueMapper = new WordCountValueMapper();
    HBaseProjectionCriteria projectionCriteria = new HBaseProjectionCriteria();
    projectionCriteria.addColumn(new HBaseProjectionCriteria.ColumnMetaData("cf", "count"));
    HBaseState.Options options = new HBaseState.Options().withConfigKey(hbaseRoot).withDurability(Durability.SYNC_WAL).withMapper(tridentHBaseMapper).withProjectionCriteria(projectionCriteria).withRowToStormValueMapper(rowToStormValueMapper).withTableName("WordCount");
    StateFactory factory = new HBaseStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new HBaseUpdater(), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new HBaseQuery(), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : HBaseUpdater(org.apache.storm.hbase.trident.state.HBaseUpdater) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) HBaseProjectionCriteria(org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria) WordCountValueMapper(org.apache.storm.hbase.topology.WordCountValueMapper) HBaseValueMapper(org.apache.storm.hbase.bolt.mapper.HBaseValueMapper) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) StateFactory(org.apache.storm.trident.state.StateFactory) HBaseStateFactory(org.apache.storm.hbase.trident.state.HBaseStateFactory) HBaseState(org.apache.storm.hbase.trident.state.HBaseState) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) SimpleTridentHBaseMapper(org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper) TridentHBaseMapper(org.apache.storm.hbase.trident.mapper.TridentHBaseMapper) HBaseQuery(org.apache.storm.hbase.trident.state.HBaseQuery)

Aggregations

HBaseProjectionCriteria (org.apache.storm.hbase.bolt.mapper.HBaseProjectionCriteria)2 Fields (org.apache.storm.tuple.Fields)2 HashMap (java.util.HashMap)1 Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)1 HBaseLookupBolt (org.apache.storm.hbase.bolt.HBaseLookupBolt)1 HBaseValueMapper (org.apache.storm.hbase.bolt.mapper.HBaseValueMapper)1 SimpleHBaseMapper (org.apache.storm.hbase.bolt.mapper.SimpleHBaseMapper)1 WordCountValueMapper (org.apache.storm.hbase.topology.WordCountValueMapper)1 SimpleTridentHBaseMapper (org.apache.storm.hbase.trident.mapper.SimpleTridentHBaseMapper)1 TridentHBaseMapper (org.apache.storm.hbase.trident.mapper.TridentHBaseMapper)1 HBaseQuery (org.apache.storm.hbase.trident.state.HBaseQuery)1 HBaseState (org.apache.storm.hbase.trident.state.HBaseState)1 HBaseStateFactory (org.apache.storm.hbase.trident.state.HBaseStateFactory)1 HBaseUpdater (org.apache.storm.hbase.trident.state.HBaseUpdater)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Stream (org.apache.storm.trident.Stream)1 TridentState (org.apache.storm.trident.TridentState)1 TridentTopology (org.apache.storm.trident.TridentTopology)1