summaryrefslogtreecommitdiff
path: root/dtrain/hstreaming/rule_count/red.rb
blob: 8f9109cc26b2ab9bedc41ce5b5cb7b0d71c16607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
STDIN.set_encoding 'utf-8'
STDOUT.set_encoding 'utf-8'

def output(key, val)
  puts "#{key}\t#{val}"
end

prev_key = nil
sum = 0
while line = STDIN.gets
   key, val = line.strip.split /\t/
   if key != prev_key && sum > 0
      output prev_key, sum
      prev_key = key
      sum = 0
   elsif !prev_key
      prev_key = key
   end
   sum += val.to_i
end
output prev_key, sum