streamingly 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in streamingly.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matt Gillooly
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Streamingly
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'streamingly'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install streamingly
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+ module Streamingly
2
+ class Reducer
3
+
4
+ def initialize(accumulator_class)
5
+ @accumulator_class = accumulator_class
6
+ end
7
+
8
+ def reduce_over(enumerator)
9
+ enumerator.each do |line|
10
+ reduce(line.strip).each do |out|
11
+ yield out
12
+ end
13
+ end
14
+
15
+ flush.each do |out|
16
+ yield out
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def flush
23
+ @accumulator ? @accumulator.flush : []
24
+ end
25
+
26
+ def reduce(line)
27
+ key, value = line.split("\t")
28
+
29
+ if @prev_key != key
30
+ results = flush
31
+
32
+ @prev_key = key
33
+ @accumulator = @accumulator_class.new(key)
34
+ end
35
+
36
+ @accumulator.apply_value(value)
37
+
38
+ results || []
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Streamingly
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "streamingly/version"
2
+ require "streamingly/reducer"
3
+
4
+ module Streamingly
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,19 @@
1
+ require 'streamingly'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Streamingly::Reducer do
4
+
5
+ let(:accumulator_class) { double }
6
+ subject { described_class.new(accumulator_class) }
7
+
8
+ describe "#reduce_over" do
9
+
10
+ context "given records with the same key" do
11
+ let(:key) { 'key' }
12
+ let(:value1) { 'asdf' }
13
+ let(:value2) { 'qwerty' }
14
+
15
+ let(:records) {
16
+ [
17
+ [key, value1].join("\t"),
18
+ [key, value2].join("\t")
19
+ ]
20
+ }
21
+
22
+ let(:accumulator) { double(:accumulator, :flush => []) }
23
+
24
+ before do
25
+ accumulator_class.stub(:new).with(key) { accumulator }
26
+ end
27
+
28
+ it "combines them into the same accumulator" do
29
+ accumulator.should_receive(:apply_value).with(value1)
30
+ accumulator.should_receive(:apply_value).with(value2)
31
+
32
+ subject.reduce_over(records)
33
+ end
34
+ end
35
+
36
+ context "given records with different keys" do
37
+ let(:key1) { 'key1' }
38
+ let(:key2) { 'key2' }
39
+ let(:value1) { 'asdf' }
40
+ let(:value2) { 'qwerty' }
41
+
42
+ let(:records) {
43
+ [
44
+ [key1, value1].join("\t"),
45
+ [key2, value2].join("\t")
46
+ ]
47
+ }
48
+
49
+ let(:accumulator1) { double(:accumulator, :flush => []) }
50
+ let(:accumulator2) { double(:accumulator, :flush => []) }
51
+
52
+ before do
53
+ accumulator_class.stub(:new).with(key1) { accumulator1 }
54
+ accumulator_class.stub(:new).with(key2) { accumulator2 }
55
+ end
56
+
57
+ it "sends them to different accumulators" do
58
+ accumulator1.should_receive(:apply_value).with(value1)
59
+ accumulator2.should_receive(:apply_value).with(value2)
60
+
61
+ subject.reduce_over(records)
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'streamingly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "streamingly"
8
+ spec.version = Streamingly::VERSION
9
+ spec.authors = ["Matt Gillooly"]
10
+ spec.email = ["matt@swipely.com"]
11
+ spec.description = %q{Helpful classes for writing streaming Hadoop jobs in Ruby}
12
+ spec.summary = %q{Helpful classes for writing streaming Hadoop jobs in Ruby}
13
+ spec.homepage = "http://github.com/swipely/streamingly"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streamingly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Gillooly
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70096429996900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70096429996900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70096429996360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70096429996360
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70096429995780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70096429995780
47
+ description: Helpful classes for writing streaming Hadoop jobs in Ruby
48
+ email:
49
+ - matt@swipely.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/streamingly.rb
61
+ - lib/streamingly/reducer.rb
62
+ - lib/streamingly/version.rb
63
+ - spec/spec_helper.rb
64
+ - spec/streamingly/reducer_spec.rb
65
+ - streamingly.gemspec
66
+ homepage: http://github.com/swipely/streamingly
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.11
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Helpful classes for writing streaming Hadoop jobs in Ruby
91
+ test_files:
92
+ - spec/spec_helper.rb
93
+ - spec/streamingly/reducer_spec.rb
94
+ has_rdoc: