Sha256: c21520779fefbe202bfe71cea995481ed615e926ef5bc83864b1cfb634ada0a6

Contents?: true

Size: 612 Bytes

Versions: 18

Compression:

Stored size: 612 Bytes

Contents

module Wukong
  module Streamer
    #
    # Emit each unique key and the count of its occurrences
    #
    class CountKeys < Wukong::Streamer::AccumulatingReducer
      attr_accessor :key_count

      def formatted_key_count
        "%10d"%key_count.to_i
      end

      # reset the counter to zero
      def start! *args
        self.key_count = 0
      end

      # record one more for this key
      def accumulate *vals
        self.key_count += 1
      end

      # emit each key field and the count, tab-separated.
      def finalize
        yield [key, formatted_key_count]
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 lib/wukong/streamer/count_keys.rb
wukong-1.5.4 lib/wukong/streamer/count_keys.rb
wukong-1.5.3 lib/wukong/streamer/count_keys.rb
wukong-1.5.2 lib/wukong/streamer/count_keys.rb
wukong-1.5.1 lib/wukong/streamer/count_keys.rb
wukong-1.5.0 lib/wukong/streamer/count_keys.rb
wukong-1.4.12 lib/wukong/streamer/count_keys.rb
wukong-1.4.11 lib/wukong/streamer/count_keys.rb
wukong-1.4.10 lib/wukong/streamer/count_keys.rb
wukong-1.4.9 lib/wukong/streamer/count_keys.rb
wukong-1.4.7 lib/wukong/streamer/count_keys.rb
wukong-1.4.6 lib/wukong/streamer/count_keys.rb
wukong-1.4.5 lib/wukong/streamer/count_keys.rb
wukong-1.4.2 lib/wukong/streamer/count_keys.rb
wukong-1.4.1 lib/wukong/streamer/count_keys.rb
wukong-1.4.0 lib/wukong/streamer/count_keys.rb
wukong-0.1.4 lib/wukong/streamer/count_keys.rb
wukong-0.1.1 lib/wukong/streamer/count_keys.rb