simpler bolt
This commit is contained in:
parent
8ba31f6a74
commit
902fb8cb9c
|
@ -1,32 +1,28 @@
|
|||
class WordCountBolt < RedStorm::SimpleBolt
|
||||
output_fields :word, :count
|
||||
|
||||
on_init {@counts = Hash.new{|h, k| h[k] = 0}}
|
||||
|
||||
on_tuple do |tuple|
|
||||
word = tuple.getString(0)
|
||||
@counts[word] += 1
|
||||
|
||||
[word, @counts[word]]
|
||||
end
|
||||
|
||||
def initialize
|
||||
@counts = Hash.new{|h, k| h[k] = 0}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# below is the same bolt but passing a method name to on_tuple
|
||||
|
||||
# class WordCountBolt < RedStorm::SimpleBolt
|
||||
|
||||
# output_fields :word, :count
|
||||
# on_tuple :count_word, :ack => true, :anchor => true
|
||||
|
||||
# on_init {@counts = Hash.new{|h, k| h[k] = 0}}
|
||||
# on_tuple :count_word
|
||||
#
|
||||
# def count_word(tuple)
|
||||
# word = tuple.getString(0)
|
||||
# @counts[word] += 1
|
||||
|
||||
#
|
||||
# [word, @counts[word]]
|
||||
# end
|
||||
|
||||
# def initialize
|
||||
# @counts = Hash.new{|h, k| h[k] = 0}
|
||||
# end
|
||||
# end
|
||||
|
|
Loading…
Reference in New Issue