fluent-plugin-droonga 0.9.0 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +8 -1
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +39 -0
- data/lib/droonga/adapter_runner.rb +99 -0
- data/lib/droonga/catalog/base.rb +11 -11
- data/lib/droonga/catalog/dataset.rb +54 -0
- data/lib/droonga/catalog/version1.rb +1 -1
- data/lib/droonga/collector.rb +5 -7
- data/lib/droonga/collector_plugin.rb +7 -7
- data/lib/droonga/command.rb +36 -0
- data/lib/droonga/{plugin/input_adapter/crud.rb → command_repository.rb} +14 -8
- data/lib/droonga/dispatcher.rb +86 -54
- data/lib/droonga/distributed_command_planner.rb +183 -0
- data/lib/droonga/distributor.rb +43 -17
- data/lib/droonga/handler.rb +13 -72
- data/lib/droonga/handler_message.rb +5 -5
- data/lib/droonga/handler_messenger.rb +4 -1
- data/lib/droonga/handler_plugin.rb +2 -2
- data/lib/droonga/handler_runner.rb +104 -0
- data/lib/droonga/input_message.rb +4 -4
- data/lib/droonga/legacy_pluggable.rb +66 -0
- data/lib/droonga/{input_adapter.rb → legacy_plugin.rb} +27 -22
- data/lib/droonga/{plugin_repository.rb → legacy_plugin_repository.rb} +2 -4
- data/lib/droonga/message_matcher.rb +101 -0
- data/lib/droonga/{input_adapter_plugin.rb → planner.rb} +14 -10
- data/lib/droonga/planner_plugin.rb +54 -0
- data/lib/droonga/pluggable.rb +9 -45
- data/lib/droonga/plugin.rb +9 -33
- data/lib/droonga/plugin/collector/basic.rb +2 -0
- data/lib/droonga/plugin/collector/search.rb +31 -37
- data/lib/droonga/plugin/{handler/groonga/table_remove.rb → metadata/adapter_message.rb} +23 -18
- data/lib/droonga/plugin/{handler/search.rb → metadata/handler_action.rb} +19 -15
- data/lib/droonga/plugin/metadata/input_message.rb +39 -0
- data/lib/droonga/plugin/planner/crud.rb +49 -0
- data/lib/droonga/plugin/{distributor → planner}/distributed_search_planner.rb +62 -70
- data/lib/droonga/plugin/{distributor → planner}/groonga.rb +11 -32
- data/lib/droonga/plugin/{distributor → planner}/search.rb +5 -5
- data/lib/droonga/plugin/{distributor → planner}/watch.rb +15 -6
- data/lib/droonga/plugin_loader.rb +10 -0
- data/lib/droonga/plugin_registerable.rb +34 -10
- data/lib/droonga/plugin_registry.rb +58 -0
- data/lib/droonga/plugins/crud.rb +124 -0
- data/lib/droonga/plugins/error.rb +50 -0
- data/lib/droonga/{output_adapter_plugin.rb → plugins/groonga.rb} +9 -13
- data/lib/droonga/plugins/groonga/column_create.rb +123 -0
- data/lib/droonga/plugins/groonga/generic_command.rb +65 -0
- data/lib/droonga/{plugin/output_adapter/groonga.rb → plugins/groonga/generic_response.rb} +16 -15
- data/lib/droonga/plugins/groonga/select.rb +124 -0
- data/lib/droonga/plugins/groonga/table_create.rb +106 -0
- data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
- data/lib/droonga/plugins/search.rb +40 -0
- data/lib/droonga/plugins/watch.rb +156 -0
- data/lib/droonga/processor.rb +8 -10
- data/lib/droonga/searcher.rb +14 -4
- data/lib/droonga/searcher/mecab_filter.rb +67 -0
- data/lib/droonga/session.rb +5 -5
- data/lib/droonga/test.rb +1 -1
- data/lib/droonga/test/stub_handler_message.rb +1 -1
- data/lib/droonga/test/{stub_distributor.rb → stub_planner.rb} +1 -1
- data/lib/droonga/worker.rb +7 -8
- data/lib/fluent/plugin/out_droonga.rb +0 -1
- data/sample/cluster/catalog.json +2 -4
- data/sample/mecab_filter/data.grn +7 -0
- data/sample/mecab_filter/ddl.grn +7 -0
- data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
- data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
- data/test/command/config/default/catalog.json +2 -5
- data/test/command/suite/search/error/no-query.expected +13 -0
- data/test/command/suite/search/error/no-query.test +7 -0
- data/test/command/suite/search/error/unknown-source.expected +26 -0
- data/test/command/suite/watch/subscribe.expected +3 -3
- data/test/command/suite/watch/unsubscribe.expected +3 -3
- data/test/unit/catalog/test_dataset.rb +385 -0
- data/test/unit/catalog/test_version1.rb +111 -45
- data/test/unit/fixtures/catalog/version1.json +0 -3
- data/test/unit/helper.rb +2 -1
- data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
- data/test/unit/plugin/collector/test_basic.rb +233 -376
- data/test/unit/plugin/collector/test_search.rb +8 -17
- data/test/unit/plugin/planner/search_planner/test_basic.rb +120 -0
- data/test/unit/plugin/planner/search_planner/test_group_by.rb +573 -0
- data/test/unit/plugin/planner/search_planner/test_output.rb +388 -0
- data/test/unit/plugin/planner/search_planner/test_sort_by.rb +938 -0
- data/test/unit/plugin/{distributor → planner}/test_search.rb +20 -75
- data/test/unit/{plugin/handler → plugins/crud}/test_add.rb +11 -11
- data/test/unit/plugins/groonga/select/test_adapter_input.rb +213 -0
- data/test/unit/{plugin/output_adapter/groonga/test_select.rb → plugins/groonga/select/test_adapter_output.rb} +12 -13
- data/test/unit/{plugin/handler → plugins}/groonga/test_column_create.rb +20 -5
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_create.rb +5 -0
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_remove.rb +8 -1
- data/test/unit/{plugin/handler → plugins}/test_groonga.rb +5 -5
- data/test/unit/{plugin/handler → plugins}/test_search.rb +21 -5
- data/test/unit/{plugin/handler → plugins}/test_watch.rb +29 -10
- data/{lib/droonga/command_mapper.rb → test/unit/test_command_repository.rb} +16 -22
- data/test/unit/{test_plugin.rb → test_legacy_plugin.rb} +3 -3
- data/test/unit/{test_plugin_repository.rb → test_legacy_plugin_repository.rb} +3 -3
- data/test/unit/test_message_matcher.rb +137 -0
- metadata +86 -66
- data/bin/grn2jsons +0 -82
- data/lib/droonga/distribution_planner.rb +0 -76
- data/lib/droonga/distributor_plugin.rb +0 -95
- data/lib/droonga/output_adapter.rb +0 -53
- data/lib/droonga/plugin/collector/groonga.rb +0 -83
- data/lib/droonga/plugin/distributor/crud.rb +0 -84
- data/lib/droonga/plugin/handler/add.rb +0 -109
- data/lib/droonga/plugin/handler/forward.rb +0 -75
- data/lib/droonga/plugin/handler/groonga.rb +0 -99
- data/lib/droonga/plugin/handler/groonga/column_create.rb +0 -106
- data/lib/droonga/plugin/handler/groonga/table_create.rb +0 -91
- data/lib/droonga/plugin/handler/watch.rb +0 -108
- data/lib/droonga/plugin/input_adapter/groonga.rb +0 -49
- data/lib/droonga/plugin/input_adapter/groonga/select.rb +0 -63
- data/lib/droonga/plugin/output_adapter/crud.rb +0 -51
- data/lib/droonga/plugin/output_adapter/groonga/select.rb +0 -54
- data/lib/groonga_command_converter.rb +0 -143
- data/sample/fluentd.conf +0 -8
- data/test/unit/plugin/distributor/test_search_planner.rb +0 -1102
- data/test/unit/plugin/input_adapter/groonga/test_select.rb +0 -248
- data/test/unit/test_command_mapper.rb +0 -44
- data/test/unit/test_groonga_command_converter.rb +0 -242
data/test/unit/helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Droonga Project
|
1
|
+
# Copyright (C) 2013-2014 Droonga Project
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -20,6 +20,7 @@ require_relative "helper/fixture"
|
|
20
20
|
require_relative "helper/stub_worker"
|
21
21
|
require_relative "helper/plugin_helper"
|
22
22
|
require_relative "helper/watch_helper"
|
23
|
+
require_relative "helper/distributed_search_planner_helper"
|
23
24
|
|
24
25
|
class Test::Unit::TestCase
|
25
26
|
include Sandbox
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "droonga/plugin/planner/distributed_search_planner"
|
17
|
+
|
18
|
+
module DistributedSearchPlannerHelper
|
19
|
+
def plan(search_request)
|
20
|
+
planner = Droonga::DistributedSearchPlanner.new(search_request)
|
21
|
+
planner.plan
|
22
|
+
end
|
23
|
+
|
24
|
+
def messages
|
25
|
+
@messages ||= plan(@request)
|
26
|
+
end
|
27
|
+
|
28
|
+
def broadcast_message
|
29
|
+
messages.find do |message|
|
30
|
+
message["type"] == "broadcast"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def reduce_message
|
35
|
+
messages.find do |message|
|
36
|
+
message["type"] == "search_reduce"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def gather_message
|
41
|
+
messages.find do |message|
|
42
|
+
message["type"] == "search_gather"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def dependencies
|
47
|
+
dependencies = messages.collect do |message|
|
48
|
+
{
|
49
|
+
"type" => message["type"],
|
50
|
+
"inputs" => message["inputs"],
|
51
|
+
"outputs" => message["outputs"],
|
52
|
+
}
|
53
|
+
end
|
54
|
+
sort_dependencies(dependencies)
|
55
|
+
end
|
56
|
+
|
57
|
+
def sort_dependencies(dependencies)
|
58
|
+
dependencies.sort do |a, b|
|
59
|
+
a["type"] <=> b["type"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def expected_dependencies(reduce_inputs, gather_inputs)
|
64
|
+
dependencies = [
|
65
|
+
{
|
66
|
+
"type" => "search_reduce",
|
67
|
+
"inputs" => reduce_inputs,
|
68
|
+
"outputs" => gather_inputs,
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"type" => "search_gather",
|
72
|
+
"inputs" => gather_inputs,
|
73
|
+
"outputs" => nil,
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"type" => "broadcast",
|
77
|
+
"inputs" => nil,
|
78
|
+
"outputs" => reduce_inputs,
|
79
|
+
},
|
80
|
+
]
|
81
|
+
sort_dependencies(dependencies)
|
82
|
+
end
|
83
|
+
end
|
@@ -40,32 +40,18 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
class
|
43
|
+
class IOTest < self
|
44
44
|
data(
|
45
45
|
:simple_mapping => {
|
46
|
-
:expected => "result",
|
46
|
+
:expected => ["output_name", "result"],
|
47
47
|
:source => "result",
|
48
|
-
:mapping => "
|
48
|
+
:mapping => "output_name",
|
49
49
|
},
|
50
50
|
:complex_mapping => {
|
51
|
-
:expected =>
|
52
|
-
|
53
|
-
"records" => [
|
54
|
-
create_record(0),
|
55
|
-
create_record(1),
|
56
|
-
create_record(2),
|
57
|
-
],
|
58
|
-
},
|
59
|
-
:source => {
|
60
|
-
"count" => 3,
|
61
|
-
"records" => [
|
62
|
-
create_record(0),
|
63
|
-
create_record(1),
|
64
|
-
create_record(2),
|
65
|
-
],
|
66
|
-
},
|
51
|
+
:expected => ["output_name", "result"],
|
52
|
+
:source => "result",
|
67
53
|
:mapping => {
|
68
|
-
"output" => "
|
54
|
+
"output" => "output_name",
|
69
55
|
},
|
70
56
|
},
|
71
57
|
)
|
@@ -73,7 +59,7 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
73
59
|
request = {
|
74
60
|
"task" => {
|
75
61
|
"values" => nil,
|
76
|
-
"
|
62
|
+
"step" => {
|
77
63
|
"body" => nil,
|
78
64
|
"outputs" => nil,
|
79
65
|
},
|
@@ -84,38 +70,23 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
84
70
|
"descendants" => nil,
|
85
71
|
}
|
86
72
|
@plugin.process("collector_gather", request)
|
87
|
-
|
88
|
-
output_name = output_name["output"] if output_name.is_a?(Hash)
|
89
|
-
assert_equal([output_name, data[:expected]], @outputs.last)
|
73
|
+
assert_equal(data[:expected], @outputs.last)
|
90
74
|
end
|
91
|
-
end
|
92
75
|
|
93
|
-
|
94
|
-
data(
|
95
|
-
:int => {
|
96
|
-
:expected => 1.5,
|
97
|
-
:value => 1,
|
98
|
-
:source => 2,
|
99
|
-
},
|
100
|
-
:float => {
|
101
|
-
:expected => 1.5,
|
102
|
-
:value => 1.0,
|
103
|
-
:source => 2.0,
|
104
|
-
},
|
105
|
-
)
|
106
|
-
def test_average(data)
|
76
|
+
def test_reduce
|
107
77
|
input_name = "input_#{Time.now.to_i}"
|
108
78
|
output_name = "output_#{Time.now.to_i}"
|
109
79
|
request = {
|
110
80
|
"task" => {
|
111
81
|
"values" => {
|
112
|
-
output_name =>
|
82
|
+
output_name => [0, 1, 2],
|
113
83
|
},
|
114
|
-
"
|
84
|
+
"step" => {
|
115
85
|
"body" => {
|
116
86
|
input_name => {
|
117
87
|
output_name => {
|
118
|
-
"type" => "
|
88
|
+
"type" => "sum",
|
89
|
+
"limit" => -1,
|
119
90
|
},
|
120
91
|
},
|
121
92
|
},
|
@@ -123,77 +94,102 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
123
94
|
},
|
124
95
|
},
|
125
96
|
"id" => nil,
|
126
|
-
"value" =>
|
97
|
+
"value" => [3, 4, 5],
|
127
98
|
"name" => input_name,
|
128
99
|
"descendants" => nil,
|
129
100
|
}
|
130
101
|
@plugin.process("collector_reduce", request)
|
131
102
|
assert_equal([
|
132
103
|
output_name,
|
133
|
-
|
104
|
+
[0, 1, 2, 3, 4, 5],
|
134
105
|
],
|
135
106
|
@outputs.last)
|
136
107
|
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class ReduceTest < self
|
111
|
+
data(
|
112
|
+
:int => {
|
113
|
+
:expected => 1.5,
|
114
|
+
:left => 1,
|
115
|
+
:right => 2,
|
116
|
+
},
|
117
|
+
:float => {
|
118
|
+
:expected => 1.5,
|
119
|
+
:left => 1.0,
|
120
|
+
:right => 2.0,
|
121
|
+
},
|
122
|
+
)
|
123
|
+
def test_average(data)
|
124
|
+
reduced = @plugin.reduce({ "type" => "average" },
|
125
|
+
data[:left],
|
126
|
+
data[:right])
|
127
|
+
assert_equal(data[:expected], reduced)
|
128
|
+
end
|
137
129
|
|
138
130
|
data(
|
139
131
|
:true_and_false => {
|
140
132
|
:expected => false,
|
141
|
-
:
|
142
|
-
:
|
133
|
+
:left => true,
|
134
|
+
:right => false,
|
143
135
|
},
|
144
136
|
:false_and_true => {
|
145
137
|
:expected => false,
|
146
|
-
:
|
147
|
-
:
|
138
|
+
:left => false,
|
139
|
+
:right => true,
|
148
140
|
},
|
149
141
|
:both_true => {
|
150
142
|
:expected => true,
|
151
|
-
:
|
152
|
-
:
|
143
|
+
:left => true,
|
144
|
+
:right => true,
|
153
145
|
},
|
154
146
|
:both_false => {
|
155
147
|
:expected => false,
|
156
|
-
:
|
157
|
-
:
|
148
|
+
:left => false,
|
149
|
+
:right => false,
|
158
150
|
},
|
159
151
|
)
|
160
152
|
def test_and(data)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
153
|
+
reduced = @plugin.reduce({ "type" => "and" },
|
154
|
+
data[:left],
|
155
|
+
data[:right])
|
156
|
+
assert_equal(data[:expected], reduced)
|
157
|
+
end
|
158
|
+
|
159
|
+
data(
|
160
|
+
:true_and_false => {
|
161
|
+
:expected => true,
|
162
|
+
:left => true,
|
163
|
+
:right => false,
|
164
|
+
},
|
165
|
+
:false_and_true => {
|
166
|
+
:expected => true,
|
167
|
+
:left => false,
|
168
|
+
:right => true,
|
169
|
+
},
|
170
|
+
:both_true => {
|
171
|
+
:expected => true,
|
172
|
+
:left => true,
|
173
|
+
:right => true,
|
174
|
+
},
|
175
|
+
:both_false => {
|
176
|
+
:expected => false,
|
177
|
+
:left => false,
|
178
|
+
:right => false,
|
179
|
+
},
|
180
|
+
)
|
181
|
+
def test_or(data)
|
182
|
+
reduced = @plugin.reduce({ "type" => "or" },
|
183
|
+
data[:left],
|
184
|
+
data[:right])
|
185
|
+
assert_equal(data[:expected], reduced)
|
190
186
|
end
|
191
187
|
|
192
188
|
data(
|
193
189
|
:numeric_values => {
|
194
190
|
:expected => 3,
|
195
|
-
:
|
196
|
-
:
|
191
|
+
:left => 1,
|
192
|
+
:right => 2,
|
197
193
|
},
|
198
194
|
:numeric_key_records => {
|
199
195
|
:expected => [
|
@@ -204,12 +200,12 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
204
200
|
create_record(5),
|
205
201
|
create_record(6),
|
206
202
|
],
|
207
|
-
:
|
203
|
+
:left => [
|
208
204
|
create_record(1),
|
209
205
|
create_record(2),
|
210
206
|
create_record(3),
|
211
207
|
],
|
212
|
-
:
|
208
|
+
:right => [
|
213
209
|
create_record(4),
|
214
210
|
create_record(5),
|
215
211
|
create_record(6),
|
@@ -224,86 +220,51 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
224
220
|
create_record("e"),
|
225
221
|
create_record("f"),
|
226
222
|
],
|
227
|
-
:
|
223
|
+
:left => [
|
228
224
|
create_record("a"),
|
229
225
|
create_record("b"),
|
230
226
|
create_record("c"),
|
231
227
|
],
|
232
|
-
:
|
228
|
+
:right => [
|
233
229
|
create_record("d"),
|
234
230
|
create_record("e"),
|
235
231
|
create_record("f"),
|
236
232
|
],
|
237
233
|
},
|
238
|
-
|
239
|
-
def test_sum(data)
|
240
|
-
input_name = "input_#{Time.now.to_i}"
|
241
|
-
output_name = "output_#{Time.now.to_i}"
|
242
|
-
request = {
|
243
|
-
"task" => {
|
244
|
-
"values" => {
|
245
|
-
output_name => data[:value],
|
246
|
-
},
|
247
|
-
"component" => {
|
248
|
-
"body" => {
|
249
|
-
input_name => {
|
250
|
-
output_name => {
|
251
|
-
"type" => "sum",
|
252
|
-
"limit" => -1,
|
253
|
-
},
|
254
|
-
},
|
255
|
-
},
|
256
|
-
"outputs" => nil,
|
257
|
-
},
|
258
|
-
},
|
259
|
-
"id" => nil,
|
260
|
-
"value" => data[:source],
|
261
|
-
"name" => input_name,
|
262
|
-
"descendants" => nil,
|
263
|
-
}
|
264
|
-
@plugin.process("collector_reduce", request)
|
265
|
-
assert_equal([
|
266
|
-
output_name,
|
267
|
-
data[:expected],
|
268
|
-
],
|
269
|
-
@outputs.last)
|
270
|
-
end
|
271
|
-
|
272
|
-
data(
|
273
|
-
:numeric_values => {
|
234
|
+
:numeric_values_with_limit => {
|
274
235
|
:expected => 3,
|
275
|
-
:
|
276
|
-
:
|
236
|
+
:left => 1,
|
237
|
+
:right => 2,
|
277
238
|
:limit => 2,
|
278
239
|
},
|
279
|
-
:
|
240
|
+
:numeric_key_records_with_limit => {
|
280
241
|
:expected => [
|
281
242
|
create_record(1),
|
282
243
|
create_record(2),
|
283
244
|
],
|
284
|
-
:
|
245
|
+
:left => [
|
285
246
|
create_record(1),
|
286
247
|
create_record(2),
|
287
248
|
create_record(3),
|
288
249
|
],
|
289
|
-
:
|
250
|
+
:right => [
|
290
251
|
create_record(4),
|
291
252
|
create_record(5),
|
292
253
|
create_record(6),
|
293
254
|
],
|
294
255
|
:limit => 2,
|
295
256
|
},
|
296
|
-
:
|
257
|
+
:string_key_records_with_limit => {
|
297
258
|
:expected => [
|
298
259
|
create_record("a"),
|
299
260
|
create_record("b"),
|
300
261
|
],
|
301
|
-
:
|
262
|
+
:left => [
|
302
263
|
create_record("a"),
|
303
264
|
create_record("b"),
|
304
265
|
create_record("c"),
|
305
266
|
],
|
306
|
-
:
|
267
|
+
:right => [
|
307
268
|
create_record("d"),
|
308
269
|
create_record("e"),
|
309
270
|
create_record("f"),
|
@@ -311,37 +272,12 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
311
272
|
:limit => 2,
|
312
273
|
},
|
313
274
|
)
|
314
|
-
def
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
output_name => data[:value],
|
321
|
-
},
|
322
|
-
"component" => {
|
323
|
-
"body" => {
|
324
|
-
input_name => {
|
325
|
-
output_name => {
|
326
|
-
"type" => "sum",
|
327
|
-
"limit" => data[:limit],
|
328
|
-
},
|
329
|
-
},
|
330
|
-
},
|
331
|
-
"outputs" => nil,
|
332
|
-
},
|
333
|
-
},
|
334
|
-
"id" => nil,
|
335
|
-
"value" => data[:source],
|
336
|
-
"name" => input_name,
|
337
|
-
"descendants" => nil,
|
338
|
-
}
|
339
|
-
@plugin.process("collector_reduce", request)
|
340
|
-
assert_equal([
|
341
|
-
output_name,
|
342
|
-
data[:expected],
|
343
|
-
],
|
344
|
-
@outputs.last)
|
275
|
+
def test_sum(data)
|
276
|
+
reduced = @plugin.reduce({ "type" => "sum",
|
277
|
+
"limit" => data[:limit] || -1 },
|
278
|
+
data[:left],
|
279
|
+
data[:right])
|
280
|
+
assert_equal(data[:expected], reduced)
|
345
281
|
end
|
346
282
|
|
347
283
|
data(
|
@@ -354,12 +290,12 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
354
290
|
create_record(5),
|
355
291
|
create_record(6),
|
356
292
|
],
|
357
|
-
:
|
293
|
+
:left => [
|
358
294
|
create_record(1),
|
359
295
|
create_record(3),
|
360
296
|
create_record(5),
|
361
297
|
],
|
362
|
-
:
|
298
|
+
:right => [
|
363
299
|
create_record(2),
|
364
300
|
create_record(4),
|
365
301
|
create_record(6),
|
@@ -374,83 +310,45 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
374
310
|
create_record("e"),
|
375
311
|
create_record("f"),
|
376
312
|
],
|
377
|
-
:
|
313
|
+
:left => [
|
378
314
|
create_record("a"),
|
379
315
|
create_record("c"),
|
380
316
|
create_record("e"),
|
381
317
|
],
|
382
|
-
:
|
318
|
+
:right => [
|
383
319
|
create_record("b"),
|
384
320
|
create_record("d"),
|
385
321
|
create_record("f"),
|
386
322
|
],
|
387
323
|
},
|
388
|
-
|
389
|
-
def test_sort(data)
|
390
|
-
input_name = "input_#{Time.now.to_i}"
|
391
|
-
output_name = "output_#{Time.now.to_i}"
|
392
|
-
request = {
|
393
|
-
"task" => {
|
394
|
-
"values" => {
|
395
|
-
output_name => data[:value],
|
396
|
-
},
|
397
|
-
"component" => {
|
398
|
-
"body" => {
|
399
|
-
input_name => {
|
400
|
-
output_name => {
|
401
|
-
"type" => "sort",
|
402
|
-
"operators" => [
|
403
|
-
{ "column" => 0, "operator" => "<" },
|
404
|
-
],
|
405
|
-
"limit" => -1,
|
406
|
-
},
|
407
|
-
},
|
408
|
-
},
|
409
|
-
"outputs" => nil,
|
410
|
-
},
|
411
|
-
},
|
412
|
-
"id" => nil,
|
413
|
-
"value" => data[:source],
|
414
|
-
"name" => input_name,
|
415
|
-
"descendants" => nil,
|
416
|
-
}
|
417
|
-
@plugin.process("collector_reduce", request)
|
418
|
-
assert_equal([
|
419
|
-
output_name,
|
420
|
-
data[:expected],
|
421
|
-
],
|
422
|
-
@outputs.last)
|
423
|
-
end
|
424
|
-
|
425
|
-
data(
|
426
|
-
:numeric_key_records => {
|
324
|
+
:numeric_key_records_with_limit => {
|
427
325
|
:expected => [
|
428
326
|
create_record(1),
|
429
327
|
create_record(2),
|
430
328
|
],
|
431
|
-
:
|
329
|
+
:left => [
|
432
330
|
create_record(1),
|
433
331
|
create_record(3),
|
434
332
|
create_record(5),
|
435
333
|
],
|
436
|
-
:
|
334
|
+
:right => [
|
437
335
|
create_record(2),
|
438
336
|
create_record(4),
|
439
337
|
create_record(6),
|
440
338
|
],
|
441
339
|
:limit => 2,
|
442
340
|
},
|
443
|
-
:
|
341
|
+
:string_key_records_with_limit => {
|
444
342
|
:expected => [
|
445
343
|
create_record("a"),
|
446
344
|
create_record("b"),
|
447
345
|
],
|
448
|
-
:
|
346
|
+
:left => [
|
449
347
|
create_record("a"),
|
450
348
|
create_record("c"),
|
451
349
|
create_record("e"),
|
452
350
|
],
|
453
|
-
:
|
351
|
+
:right => [
|
454
352
|
create_record("b"),
|
455
353
|
create_record("d"),
|
456
354
|
create_record("f"),
|
@@ -458,178 +356,137 @@ class BasicCollectorTest < Test::Unit::TestCase
|
|
458
356
|
:limit => 2,
|
459
357
|
},
|
460
358
|
)
|
461
|
-
def
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
output_name => {
|
473
|
-
"type" => "sort",
|
474
|
-
"operators" => [
|
475
|
-
{ "column" => 0, "operator" => "<" },
|
476
|
-
],
|
477
|
-
"limit" => 2,
|
478
|
-
},
|
479
|
-
},
|
480
|
-
},
|
481
|
-
"outputs" => nil,
|
482
|
-
},
|
483
|
-
},
|
484
|
-
"id" => nil,
|
485
|
-
"value" => data[:source],
|
486
|
-
"name" => input_name,
|
487
|
-
"descendants" => nil,
|
488
|
-
}
|
489
|
-
@plugin.process("collector_reduce", request)
|
490
|
-
assert_equal([
|
491
|
-
output_name,
|
492
|
-
data[:expected],
|
493
|
-
],
|
494
|
-
@outputs.last)
|
359
|
+
def test_sort(data)
|
360
|
+
reduced = @plugin.reduce({
|
361
|
+
"type" => "sort",
|
362
|
+
"operators" => [
|
363
|
+
{ "column" => 0, "operator" => "<" },
|
364
|
+
],
|
365
|
+
"limit" => data[:limit] || -1,
|
366
|
+
},
|
367
|
+
data[:left],
|
368
|
+
data[:right])
|
369
|
+
assert_equal(data[:expected], reduced)
|
495
370
|
end
|
496
371
|
end
|
497
372
|
|
498
373
|
class MergeTest < self
|
499
374
|
def test_grouped
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
[
|
510
|
-
create_record(1),
|
511
|
-
create_record(3),
|
512
|
-
create_record(5),
|
513
|
-
],
|
514
|
-
],
|
515
|
-
[
|
516
|
-
"group2",
|
517
|
-
20,
|
518
|
-
[
|
519
|
-
create_record("a"),
|
520
|
-
create_record("c"),
|
521
|
-
create_record("e"),
|
522
|
-
],
|
523
|
-
],
|
524
|
-
[
|
525
|
-
"group3",
|
526
|
-
30,
|
527
|
-
[
|
528
|
-
create_record("A"),
|
529
|
-
create_record("B"),
|
530
|
-
create_record("C"),
|
531
|
-
],
|
532
|
-
],
|
533
|
-
],
|
534
|
-
},
|
535
|
-
"component" => {
|
536
|
-
"body" => {
|
537
|
-
input_name => {
|
538
|
-
output_name => {
|
539
|
-
"type" => "sort",
|
540
|
-
"operators" => [
|
541
|
-
{ "column" => 1, "operator" => "<" },
|
542
|
-
],
|
543
|
-
"key_column" => 0,
|
544
|
-
"limit" => -1,
|
545
|
-
},
|
546
|
-
},
|
547
|
-
},
|
548
|
-
"outputs" => nil,
|
549
|
-
},
|
550
|
-
},
|
551
|
-
"id" => nil,
|
552
|
-
"value" => [
|
553
|
-
[
|
554
|
-
"group1",
|
555
|
-
30,
|
556
|
-
[
|
557
|
-
create_record(2),
|
558
|
-
create_record(4),
|
559
|
-
create_record(6),
|
560
|
-
],
|
561
|
-
],
|
562
|
-
[
|
563
|
-
"group2",
|
564
|
-
40,
|
565
|
-
[
|
566
|
-
create_record("b"),
|
567
|
-
create_record("d"),
|
568
|
-
create_record("f"),
|
569
|
-
],
|
570
|
-
],
|
571
|
-
[
|
572
|
-
"group4",
|
573
|
-
50,
|
574
|
-
[
|
575
|
-
create_record("D"),
|
576
|
-
create_record("E"),
|
577
|
-
create_record("F"),
|
578
|
-
],
|
579
|
-
],
|
375
|
+
expected = [
|
376
|
+
[
|
377
|
+
"group3",
|
378
|
+
30,
|
379
|
+
[
|
380
|
+
create_record("A"),
|
381
|
+
create_record("B"),
|
382
|
+
create_record("C"),
|
383
|
+
],
|
580
384
|
],
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
385
|
+
[
|
386
|
+
"group1",
|
387
|
+
40,
|
388
|
+
[
|
389
|
+
create_record(2),
|
390
|
+
create_record(4),
|
391
|
+
create_record(6),
|
392
|
+
create_record(1),
|
393
|
+
create_record(3),
|
394
|
+
create_record(5),
|
395
|
+
],
|
396
|
+
],
|
397
|
+
[
|
398
|
+
"group4",
|
399
|
+
50,
|
400
|
+
[
|
401
|
+
create_record("D"),
|
402
|
+
create_record("E"),
|
403
|
+
create_record("F"),
|
404
|
+
],
|
405
|
+
],
|
406
|
+
[
|
407
|
+
"group2",
|
408
|
+
60,
|
409
|
+
[
|
410
|
+
create_record("b"),
|
411
|
+
create_record("d"),
|
412
|
+
create_record("f"),
|
413
|
+
create_record("a"),
|
414
|
+
create_record("c"),
|
415
|
+
create_record("e"),
|
416
|
+
],
|
417
|
+
],
|
418
|
+
]
|
419
|
+
|
420
|
+
left = [
|
421
|
+
[
|
422
|
+
"group1",
|
423
|
+
10,
|
424
|
+
[
|
425
|
+
create_record(1),
|
426
|
+
create_record(3),
|
427
|
+
create_record(5),
|
428
|
+
],
|
429
|
+
],
|
430
|
+
[
|
431
|
+
"group2",
|
432
|
+
20,
|
433
|
+
[
|
434
|
+
create_record("a"),
|
435
|
+
create_record("c"),
|
436
|
+
create_record("e"),
|
437
|
+
],
|
438
|
+
],
|
439
|
+
[
|
440
|
+
"group3",
|
441
|
+
30,
|
442
|
+
[
|
443
|
+
create_record("A"),
|
444
|
+
create_record("B"),
|
445
|
+
create_record("C"),
|
446
|
+
],
|
447
|
+
],
|
448
|
+
]
|
449
|
+
right = [
|
450
|
+
[
|
451
|
+
"group1",
|
452
|
+
30,
|
453
|
+
[
|
454
|
+
create_record(2),
|
455
|
+
create_record(4),
|
456
|
+
create_record(6),
|
457
|
+
],
|
458
|
+
],
|
459
|
+
[
|
460
|
+
"group2",
|
461
|
+
40,
|
462
|
+
[
|
463
|
+
create_record("b"),
|
464
|
+
create_record("d"),
|
465
|
+
create_record("f"),
|
466
|
+
],
|
467
|
+
],
|
468
|
+
[
|
469
|
+
"group4",
|
470
|
+
50,
|
471
|
+
[
|
472
|
+
create_record("D"),
|
473
|
+
create_record("E"),
|
474
|
+
create_record("F"),
|
475
|
+
],
|
476
|
+
],
|
477
|
+
]
|
478
|
+
|
479
|
+
reduced = @plugin.reduce({
|
480
|
+
"type" => "sort",
|
481
|
+
"operators" => [
|
482
|
+
{ "column" => 1, "operator" => "<" },
|
483
|
+
],
|
484
|
+
"key_column" => 0,
|
485
|
+
"limit" => -1,
|
486
|
+
},
|
487
|
+
left,
|
488
|
+
right)
|
489
|
+
assert_equal(expected, reduced)
|
633
490
|
end
|
634
491
|
end
|
635
492
|
end
|