match_reduce 1.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +23 -0
- data/.ruby-version +1 -0
- data/.travis.yml +25 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Guardfile +22 -0
- data/LICENSE +7 -0
- data/README.md +247 -0
- data/Rakefile +17 -0
- data/bin/console +18 -0
- data/lib/match_reduce/aggregate.rb +61 -0
- data/lib/match_reduce/any.rb +30 -0
- data/lib/match_reduce/index.rb +53 -0
- data/lib/match_reduce/processor/result.rb +37 -0
- data/lib/match_reduce/processor/result_builder.rb +55 -0
- data/lib/match_reduce/processor/results_builder.rb +40 -0
- data/lib/match_reduce/processor.rb +78 -0
- data/lib/match_reduce/version.rb +12 -0
- data/lib/match_reduce.rb +35 -0
- data/match_reduce.gemspec +35 -0
- data/spec/fixtures/snapshots/processor/abstract.yaml +68 -0
- data/spec/fixtures/snapshots/processor/teams_and_players.yaml +173 -0
- data/spec/match_reduce/aggregate_spec.rb +32 -0
- data/spec/match_reduce/any_spec.rb +32 -0
- data/spec/match_reduce/index_spec.rb +93 -0
- data/spec/match_reduce/processor/result_spec.rb +48 -0
- data/spec/match_reduce/processor_spec.rb +62 -0
- data/spec/match_reduce_spec.rb +39 -0
- data/spec/spec_helper.rb +52 -0
- metadata +232 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'spec_helper'
|
11
|
+
|
12
|
+
describe MatchReduce::Processor do
|
13
|
+
def make_sum_reducer(key)
|
14
|
+
return nil if key.to_s.empty?
|
15
|
+
|
16
|
+
->(memo, record, resolver) { memo.to_i + resolver.get(record, key).to_i }
|
17
|
+
end
|
18
|
+
|
19
|
+
def snapshot(snapshot)
|
20
|
+
records = snapshot.fetch('records', [])
|
21
|
+
aggregates = snapshot.fetch('aggregates', []).map do |a|
|
22
|
+
{
|
23
|
+
name: a['name'],
|
24
|
+
patterns: a['patterns'],
|
25
|
+
reducer: make_sum_reducer(a['sum_reducer_key']),
|
26
|
+
group_keys: a['group_keys']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
results = snapshot.fetch('results', []).map do |r|
|
31
|
+
MatchReduce::Processor::Result.new(r['name'], r['records'], r['value'])
|
32
|
+
end
|
33
|
+
|
34
|
+
OpenStruct.new(
|
35
|
+
records: records,
|
36
|
+
aggregates: aggregates,
|
37
|
+
results: results
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:resolver) { Objectable.resolver }
|
42
|
+
|
43
|
+
describe 'snapshots' do
|
44
|
+
yaml_fixture_files('snapshots', 'processor').each_pair do |filename, snapshot_config|
|
45
|
+
specify File.basename(filename) do
|
46
|
+
example = snapshot(snapshot_config)
|
47
|
+
|
48
|
+
subject = described_class.new(example.aggregates, resolver)
|
49
|
+
|
50
|
+
results = subject.add_each(example.records).results
|
51
|
+
|
52
|
+
err_msg = "invalid: #{example.results.length} results != #{example.aggregates.length} aggs"
|
53
|
+
|
54
|
+
expect(example.results.length).to eq(example.aggregates.length), err_msg
|
55
|
+
|
56
|
+
results.each_with_index do |result, i|
|
57
|
+
expect(result).to eq(example.results[i])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'spec_helper'
|
11
|
+
|
12
|
+
class ProcessorMock
|
13
|
+
def initialize(_aggregates, _resolver); end
|
14
|
+
|
15
|
+
def add_each(_records)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def results
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe MatchReduce do
|
25
|
+
specify '#process should create new Processor, call add_each, then call results' do
|
26
|
+
resolver = nil
|
27
|
+
aggregates = []
|
28
|
+
records = []
|
29
|
+
results = []
|
30
|
+
|
31
|
+
processor = ProcessorMock.new(aggregates, resolver)
|
32
|
+
|
33
|
+
expect(MatchReduce::Processor).to receive(:new).with(aggregates, resolver).and_return(processor)
|
34
|
+
expect(processor).to receive(:add_each).with(records).and_return(processor)
|
35
|
+
expect(processor).to receive(:results).and_return(results)
|
36
|
+
|
37
|
+
described_class.process(aggregates, records, resolver)
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
unless ENV['DISABLE_SIMPLECOV'] == 'true'
|
14
|
+
require 'simplecov'
|
15
|
+
require 'simplecov-console'
|
16
|
+
|
17
|
+
SimpleCov.formatter = SimpleCov::Formatter::Console
|
18
|
+
SimpleCov.start do
|
19
|
+
add_filter %r{\A/spec/}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require './lib/match_reduce'
|
24
|
+
|
25
|
+
def fixture_path(*filename)
|
26
|
+
File.join('spec', 'fixtures', filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
def yaml_fixture(*filename)
|
30
|
+
YAML.safe_load(fixture(*filename))
|
31
|
+
end
|
32
|
+
|
33
|
+
def fixture(*filename)
|
34
|
+
File.open(fixture_path(*filename), 'r:bom|utf-8').read
|
35
|
+
end
|
36
|
+
|
37
|
+
def yaml_read(filename)
|
38
|
+
YAML.safe_load(read(filename))
|
39
|
+
end
|
40
|
+
|
41
|
+
def read(filename)
|
42
|
+
File.open(filename, 'r:bom|utf-8').read
|
43
|
+
end
|
44
|
+
|
45
|
+
def yaml_fixture_files(*directory)
|
46
|
+
Dir[fixture_path(*directory, '*.yaml')].map do |filename|
|
47
|
+
[
|
48
|
+
filename,
|
49
|
+
yaml_read(filename)
|
50
|
+
]
|
51
|
+
end.to_h
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: match_reduce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Ruggio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: acts_as_hashable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hash_math
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.0.0.pre.alpha
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0.pre.alpha
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: objectable
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: guard-rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.7'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '4.7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: pry
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '12'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '12'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.74.0
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.74.0
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: simplecov
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.17.0
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.17.0
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: simplecov-console
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.5.0
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.5.0
|
159
|
+
description: " High speed data aggregator and reducer algorithm based on key-value
|
160
|
+
exact matching and grouping.\n"
|
161
|
+
email:
|
162
|
+
- mruggio@bluemarblepayroll.com
|
163
|
+
executables:
|
164
|
+
- console
|
165
|
+
extensions: []
|
166
|
+
extra_rdoc_files: []
|
167
|
+
files:
|
168
|
+
- ".editorconfig"
|
169
|
+
- ".gitignore"
|
170
|
+
- ".rubocop.yml"
|
171
|
+
- ".ruby-version"
|
172
|
+
- ".travis.yml"
|
173
|
+
- CHANGELOG.md
|
174
|
+
- CODE_OF_CONDUCT.md
|
175
|
+
- Gemfile
|
176
|
+
- Guardfile
|
177
|
+
- LICENSE
|
178
|
+
- README.md
|
179
|
+
- Rakefile
|
180
|
+
- bin/console
|
181
|
+
- lib/match_reduce.rb
|
182
|
+
- lib/match_reduce/aggregate.rb
|
183
|
+
- lib/match_reduce/any.rb
|
184
|
+
- lib/match_reduce/index.rb
|
185
|
+
- lib/match_reduce/processor.rb
|
186
|
+
- lib/match_reduce/processor/result.rb
|
187
|
+
- lib/match_reduce/processor/result_builder.rb
|
188
|
+
- lib/match_reduce/processor/results_builder.rb
|
189
|
+
- lib/match_reduce/version.rb
|
190
|
+
- match_reduce.gemspec
|
191
|
+
- spec/fixtures/snapshots/processor/abstract.yaml
|
192
|
+
- spec/fixtures/snapshots/processor/teams_and_players.yaml
|
193
|
+
- spec/match_reduce/aggregate_spec.rb
|
194
|
+
- spec/match_reduce/any_spec.rb
|
195
|
+
- spec/match_reduce/index_spec.rb
|
196
|
+
- spec/match_reduce/processor/result_spec.rb
|
197
|
+
- spec/match_reduce/processor_spec.rb
|
198
|
+
- spec/match_reduce_spec.rb
|
199
|
+
- spec/spec_helper.rb
|
200
|
+
homepage: https://github.com/bluemarblepayroll/match_reduce
|
201
|
+
licenses:
|
202
|
+
- MIT
|
203
|
+
metadata: {}
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: 2.3.8
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ">"
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: 1.3.1
|
218
|
+
requirements: []
|
219
|
+
rubygems_version: 3.0.3
|
220
|
+
signing_key:
|
221
|
+
specification_version: 4
|
222
|
+
summary: Dataset aggregation and reducer algorithm
|
223
|
+
test_files:
|
224
|
+
- spec/fixtures/snapshots/processor/abstract.yaml
|
225
|
+
- spec/fixtures/snapshots/processor/teams_and_players.yaml
|
226
|
+
- spec/match_reduce/aggregate_spec.rb
|
227
|
+
- spec/match_reduce/any_spec.rb
|
228
|
+
- spec/match_reduce/index_spec.rb
|
229
|
+
- spec/match_reduce/processor/result_spec.rb
|
230
|
+
- spec/match_reduce/processor_spec.rb
|
231
|
+
- spec/match_reduce_spec.rb
|
232
|
+
- spec/spec_helper.rb
|