forked from heibaiying/BigData-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85f2539
commit 756d0eb
Showing
22 changed files
with
514 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
code/Storm/storm-hbase-integration/src/main/java/com/heibaiying/component/CountBolt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.heibaiying.component; | ||
|
||
import org.apache.storm.task.OutputCollector; | ||
import org.apache.storm.task.TopologyContext; | ||
import org.apache.storm.topology.OutputFieldsDeclarer; | ||
import org.apache.storm.topology.base.BaseRichBolt; | ||
import org.apache.storm.tuple.Fields; | ||
import org.apache.storm.tuple.Tuple; | ||
import org.apache.storm.tuple.Values; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 进行词频统计 | ||
*/ | ||
public class CountBolt extends BaseRichBolt { | ||
|
||
private Map<String, Integer> counts = new HashMap<>(); | ||
|
||
private OutputCollector collector; | ||
|
||
|
||
@Override | ||
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { | ||
this.collector=collector; | ||
} | ||
|
||
@Override | ||
public void execute(Tuple input) { | ||
String word = input.getStringByField("word"); | ||
Integer count = counts.get(word); | ||
if (count == null) { | ||
count = 0; | ||
} | ||
count++; | ||
counts.put(word, count); | ||
// 输出 | ||
collector.emit(new Values(word, String.valueOf(count))); | ||
|
||
} | ||
|
||
@Override | ||
public void declareOutputFields(OutputFieldsDeclarer declarer) { | ||
declarer.declare(new Fields("word", "count")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
code/Storm/storm-hbase-integration/src/main/resources/assembly.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.