droonga-engine 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Rakefile +6 -0
- data/bin/droonga-engine-absorb-data +14 -14
- data/bin/droonga-engine-catalog-generate +24 -12
- data/bin/droonga-engine-catalog-modify +13 -7
- data/bin/droonga-engine-join +8 -8
- data/bin/droonga-engine-set-role +1 -1
- data/bin/droonga-engine-unjoin +2 -2
- data/lib/droonga/address.rb +3 -0
- data/lib/droonga/cluster.rb +16 -10
- data/lib/droonga/command/droonga_engine_service.rb +5 -2
- data/lib/droonga/command/remote_command_base.rb +3 -3
- data/lib/droonga/distributed_command_planner.rb +11 -1
- data/lib/droonga/engine.rb +12 -11
- data/lib/droonga/engine/version.rb +2 -2
- data/lib/droonga/engine_node.rb +28 -28
- data/lib/droonga/engine_state.rb +41 -36
- data/lib/droonga/forward_buffer.rb +21 -10
- data/lib/droonga/node_role.rb +2 -0
- data/lib/droonga/plugins/groonga/select.rb +3 -0
- data/lib/droonga/plugins/search.rb +3 -1
- data/lib/droonga/plugins/search/distributed_search_planner.rb +17 -5
- data/lib/droonga/plugins/system/statistics.rb +1 -0
- data/lib/droonga/searcher.rb +13 -4
- data/test/command/config/single_slice/catalog.json +38 -0
- data/test/command/config/single_slice/droonga-engine.yaml +4 -0
- data/test/command/run-test.rb +3 -2
- data/test/command/suite/catalog/fetch.expected.single_slice +50 -0
- data/test/command/suite/dump/column/index.expected.single_slice +86 -0
- data/test/command/suite/dump/column/scalar.expected.single_slice +52 -0
- data/test/command/suite/dump/column/vector.expected.single_slice +55 -0
- data/test/command/suite/dump/record/scalar.expected.single_slice +52 -0
- data/test/command/suite/dump/record/vector/reference.expected.single_slice +117 -0
- data/test/command/suite/dump/table/array.expected.single_slice +39 -0
- data/test/command/suite/dump/table/double_array_trie.expected.single_slice +40 -0
- data/test/command/suite/dump/table/hash.expected.single_slice +40 -0
- data/test/command/suite/dump/table/patricia_trie.expected.single_slice +40 -0
- data/test/command/suite/message/error/missing-dataset.test +3 -0
- data/test/command/suite/search/condition/query/nonexistent_column.expected.single_slice +26 -0
- data/test/command/suite/search/condition/query/syntax_error.expected.single_slice +26 -0
- data/test/command/suite/search/error/unknown-source.expected.single_slice +28 -0
- data/test/command/suite/search/output/attributes/invalid.expected.single_slice +24 -0
- data/test/command/suite/system/absorb-data/records.catalog.json.single_slice +44 -0
- data/test/command/suite/system/absorb-data/records.expected.single_slice +32 -0
- data/test/command/suite/system/statistics/object/count/per-volume/empty.test +1 -0
- data/test/command/suite/system/statistics/object/count/record.expected.single_slice +11 -0
- data/test/command/suite/system/statistics/object/count/schema.expected.single_slice +11 -0
- data/test/unit/catalog/test_generator.rb +3 -2
- data/test/unit/helper.rb +2 -1
- data/test/unit/helper/stub_serf.rb +28 -0
- data/test/unit/plugins/system/statistics/test_object_count.rb +135 -0
- data/test/unit/plugins/system/statistics/test_object_count_per_volume.rb +149 -0
- data/test/unit/plugins/test_basic.rb +0 -406
- data/test/unit/test_address.rb +111 -10
- data/test/unit/test_cluster.rb +232 -0
- data/test/unit/test_differ.rb +49 -0
- data/test/unit/test_engine_node.rb +556 -0
- data/test/unit/test_engine_state.rb +151 -0
- data/test/unit/test_forward_buffer.rb +106 -0
- data/test/unit/test_node_name.rb +160 -0
- data/test/unit/test_node_role.rb +53 -0
- data/test/unit/test_reducer.rb +525 -0
- metadata +111 -49
@@ -0,0 +1,525 @@
|
|
1
|
+
# Copyright (C) 2013-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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
|
+
|
16
|
+
require "droonga/reducer"
|
17
|
+
|
18
|
+
class ReducerTest < Test::Unit::TestCase
|
19
|
+
private
|
20
|
+
def create_record(*columns)
|
21
|
+
columns
|
22
|
+
end
|
23
|
+
|
24
|
+
def reduce_value(deal, left_value, right_value)
|
25
|
+
reducer = Droonga::Reducer.new(deal)
|
26
|
+
reducer.reduce(left_value, right_value)
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def create_record(*columns)
|
31
|
+
columns
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
data(
|
36
|
+
:int => {
|
37
|
+
:expected => 3,
|
38
|
+
:left => 1,
|
39
|
+
:right => 2,
|
40
|
+
},
|
41
|
+
:float => {
|
42
|
+
:expected => 3.0,
|
43
|
+
:left => 1.0,
|
44
|
+
:right => 2.0,
|
45
|
+
},
|
46
|
+
:string => {
|
47
|
+
:expected => "ab",
|
48
|
+
:left => "a",
|
49
|
+
:right => "b",
|
50
|
+
},
|
51
|
+
:array => {
|
52
|
+
:expected => [0, 1],
|
53
|
+
:left => [0],
|
54
|
+
:right => [1],
|
55
|
+
},
|
56
|
+
:hash => {
|
57
|
+
:expected => {:a => 0, :b => 1, :c => 2},
|
58
|
+
:left => {:a => 0, :c => 2},
|
59
|
+
:right => {:b => 1, :c => 3},
|
60
|
+
},
|
61
|
+
:nested_hash => {
|
62
|
+
:expected => {:a => 0, :b => 1, :c => {:d => 2}},
|
63
|
+
:left => {:a => 0, :c => {:d => 2}},
|
64
|
+
:right => {:b => 1, :c => {:e => 3}},
|
65
|
+
},
|
66
|
+
:nil_left => {
|
67
|
+
:expected => 0,
|
68
|
+
:left => nil,
|
69
|
+
:right => 0,
|
70
|
+
},
|
71
|
+
:nil_right => {
|
72
|
+
:expected => 0,
|
73
|
+
:left => 0,
|
74
|
+
:right => nil,
|
75
|
+
},
|
76
|
+
:nil_both => {
|
77
|
+
:expected => nil,
|
78
|
+
:left => nil,
|
79
|
+
:right => nil,
|
80
|
+
},
|
81
|
+
)
|
82
|
+
def test_sum(data)
|
83
|
+
reduced = reduce_value({ "type" => "sum" },
|
84
|
+
data[:left],
|
85
|
+
data[:right])
|
86
|
+
assert_equal(data[:expected], reduced)
|
87
|
+
end
|
88
|
+
|
89
|
+
data(
|
90
|
+
:int => {
|
91
|
+
:expected => 3,
|
92
|
+
:left => 1,
|
93
|
+
:right => 2,
|
94
|
+
},
|
95
|
+
:float => {
|
96
|
+
:expected => 3.0,
|
97
|
+
:left => 1.0,
|
98
|
+
:right => 2.0,
|
99
|
+
},
|
100
|
+
:string => {
|
101
|
+
:expected => "ab",
|
102
|
+
:left => "a",
|
103
|
+
:right => "b",
|
104
|
+
},
|
105
|
+
:array => {
|
106
|
+
:expected => [3],
|
107
|
+
:left => [1],
|
108
|
+
:right => [2],
|
109
|
+
},
|
110
|
+
:hash => {
|
111
|
+
:expected => {:a => 0, :b => 1, :c => 5},
|
112
|
+
:left => {:a => 0, :c => 2},
|
113
|
+
:right => {:b => 1, :c => 3},
|
114
|
+
},
|
115
|
+
:nested_hash => {
|
116
|
+
:expected => {:a => 0, :b => 1, :c => {:d => 2, :e => 3}},
|
117
|
+
:left => {:a => 0, :c => {:d => 2}},
|
118
|
+
:right => {:b => 1, :c => {:e => 3}},
|
119
|
+
},
|
120
|
+
:nil_left => {
|
121
|
+
:expected => 0,
|
122
|
+
:left => nil,
|
123
|
+
:right => 0,
|
124
|
+
},
|
125
|
+
:nil_right => {
|
126
|
+
:expected => 0,
|
127
|
+
:left => 0,
|
128
|
+
:right => nil,
|
129
|
+
},
|
130
|
+
:nil_both => {
|
131
|
+
:expected => nil,
|
132
|
+
:left => nil,
|
133
|
+
:right => nil,
|
134
|
+
},
|
135
|
+
)
|
136
|
+
def test_recursive_sum(data)
|
137
|
+
reduced = reduce_value({ "type" => "recursive-sum" },
|
138
|
+
data[:left],
|
139
|
+
data[:right])
|
140
|
+
assert_equal(data[:expected], reduced)
|
141
|
+
end
|
142
|
+
|
143
|
+
data(
|
144
|
+
:int => {
|
145
|
+
:expected => 1.5,
|
146
|
+
:left => 1,
|
147
|
+
:right => 2,
|
148
|
+
},
|
149
|
+
:float => {
|
150
|
+
:expected => 1.5,
|
151
|
+
:left => 1.0,
|
152
|
+
:right => 2.0,
|
153
|
+
},
|
154
|
+
)
|
155
|
+
def test_average(data)
|
156
|
+
reduced = reduce_value({ "type" => "average" },
|
157
|
+
data[:left],
|
158
|
+
data[:right])
|
159
|
+
assert_equal(data[:expected], reduced)
|
160
|
+
end
|
161
|
+
|
162
|
+
data(
|
163
|
+
:true_and_false => {
|
164
|
+
:expected => false,
|
165
|
+
:left => true,
|
166
|
+
:right => false,
|
167
|
+
},
|
168
|
+
:false_and_true => {
|
169
|
+
:expected => false,
|
170
|
+
:left => false,
|
171
|
+
:right => true,
|
172
|
+
},
|
173
|
+
:both_true => {
|
174
|
+
:expected => true,
|
175
|
+
:left => true,
|
176
|
+
:right => true,
|
177
|
+
},
|
178
|
+
:both_false => {
|
179
|
+
:expected => false,
|
180
|
+
:left => false,
|
181
|
+
:right => false,
|
182
|
+
},
|
183
|
+
)
|
184
|
+
def test_and(data)
|
185
|
+
reduced = reduce_value({ "type" => "and" },
|
186
|
+
data[:left],
|
187
|
+
data[:right])
|
188
|
+
assert_equal(data[:expected], reduced)
|
189
|
+
end
|
190
|
+
|
191
|
+
data(
|
192
|
+
:true_and_false => {
|
193
|
+
:expected => true,
|
194
|
+
:left => true,
|
195
|
+
:right => false,
|
196
|
+
},
|
197
|
+
:false_and_true => {
|
198
|
+
:expected => true,
|
199
|
+
:left => false,
|
200
|
+
:right => true,
|
201
|
+
},
|
202
|
+
:both_true => {
|
203
|
+
:expected => true,
|
204
|
+
:left => true,
|
205
|
+
:right => true,
|
206
|
+
},
|
207
|
+
:both_false => {
|
208
|
+
:expected => false,
|
209
|
+
:left => false,
|
210
|
+
:right => false,
|
211
|
+
},
|
212
|
+
)
|
213
|
+
def test_or(data)
|
214
|
+
reduced = reduce_value({ "type" => "or" },
|
215
|
+
data[:left],
|
216
|
+
data[:right])
|
217
|
+
assert_equal(data[:expected], reduced)
|
218
|
+
end
|
219
|
+
|
220
|
+
class ReduceRecords < self
|
221
|
+
data(
|
222
|
+
:numeric_values => {
|
223
|
+
:expected => 3,
|
224
|
+
:left => 1,
|
225
|
+
:right => 2,
|
226
|
+
},
|
227
|
+
:numeric_key_records => {
|
228
|
+
:expected => [
|
229
|
+
create_record(1),
|
230
|
+
create_record(2),
|
231
|
+
create_record(3),
|
232
|
+
create_record(4),
|
233
|
+
create_record(5),
|
234
|
+
create_record(6),
|
235
|
+
],
|
236
|
+
:left => [
|
237
|
+
create_record(1),
|
238
|
+
create_record(2),
|
239
|
+
create_record(3),
|
240
|
+
],
|
241
|
+
:right => [
|
242
|
+
create_record(4),
|
243
|
+
create_record(5),
|
244
|
+
create_record(6),
|
245
|
+
],
|
246
|
+
},
|
247
|
+
:string_key_records => {
|
248
|
+
:expected => [
|
249
|
+
create_record("a"),
|
250
|
+
create_record("b"),
|
251
|
+
create_record("c"),
|
252
|
+
create_record("d"),
|
253
|
+
create_record("e"),
|
254
|
+
create_record("f"),
|
255
|
+
],
|
256
|
+
:left => [
|
257
|
+
create_record("a"),
|
258
|
+
create_record("b"),
|
259
|
+
create_record("c"),
|
260
|
+
],
|
261
|
+
:right => [
|
262
|
+
create_record("d"),
|
263
|
+
create_record("e"),
|
264
|
+
create_record("f"),
|
265
|
+
],
|
266
|
+
},
|
267
|
+
:numeric_values_with_limit => {
|
268
|
+
:expected => 3,
|
269
|
+
:left => 1,
|
270
|
+
:right => 2,
|
271
|
+
:limit => 2,
|
272
|
+
},
|
273
|
+
:numeric_key_records_with_limit => {
|
274
|
+
:expected => [
|
275
|
+
create_record(1),
|
276
|
+
create_record(2),
|
277
|
+
],
|
278
|
+
:left => [
|
279
|
+
create_record(1),
|
280
|
+
create_record(2),
|
281
|
+
create_record(3),
|
282
|
+
],
|
283
|
+
:right => [
|
284
|
+
create_record(4),
|
285
|
+
create_record(5),
|
286
|
+
create_record(6),
|
287
|
+
],
|
288
|
+
:limit => 2,
|
289
|
+
},
|
290
|
+
:string_key_records_with_limit => {
|
291
|
+
:expected => [
|
292
|
+
create_record("a"),
|
293
|
+
create_record("b"),
|
294
|
+
],
|
295
|
+
:left => [
|
296
|
+
create_record("a"),
|
297
|
+
create_record("b"),
|
298
|
+
create_record("c"),
|
299
|
+
],
|
300
|
+
:right => [
|
301
|
+
create_record("d"),
|
302
|
+
create_record("e"),
|
303
|
+
create_record("f"),
|
304
|
+
],
|
305
|
+
:limit => 2,
|
306
|
+
},
|
307
|
+
)
|
308
|
+
def test_sum(data)
|
309
|
+
reduced = reduce_value({ "type" => "sum",
|
310
|
+
"limit" => data[:limit] || -1 },
|
311
|
+
data[:left],
|
312
|
+
data[:right])
|
313
|
+
assert_equal(data[:expected], reduced)
|
314
|
+
end
|
315
|
+
|
316
|
+
data(
|
317
|
+
:numeric_key_records => {
|
318
|
+
:expected => [
|
319
|
+
create_record(1),
|
320
|
+
create_record(2),
|
321
|
+
create_record(3),
|
322
|
+
create_record(4),
|
323
|
+
create_record(5),
|
324
|
+
create_record(6),
|
325
|
+
],
|
326
|
+
:left => [
|
327
|
+
create_record(1),
|
328
|
+
create_record(3),
|
329
|
+
create_record(5),
|
330
|
+
],
|
331
|
+
:right => [
|
332
|
+
create_record(2),
|
333
|
+
create_record(4),
|
334
|
+
create_record(6),
|
335
|
+
],
|
336
|
+
},
|
337
|
+
:string_key_records => {
|
338
|
+
:expected => [
|
339
|
+
create_record("a"),
|
340
|
+
create_record("b"),
|
341
|
+
create_record("c"),
|
342
|
+
create_record("d"),
|
343
|
+
create_record("e"),
|
344
|
+
create_record("f"),
|
345
|
+
],
|
346
|
+
:left => [
|
347
|
+
create_record("a"),
|
348
|
+
create_record("c"),
|
349
|
+
create_record("e"),
|
350
|
+
],
|
351
|
+
:right => [
|
352
|
+
create_record("b"),
|
353
|
+
create_record("d"),
|
354
|
+
create_record("f"),
|
355
|
+
],
|
356
|
+
},
|
357
|
+
:numeric_key_records_with_limit => {
|
358
|
+
:expected => [
|
359
|
+
create_record(1),
|
360
|
+
create_record(2),
|
361
|
+
],
|
362
|
+
:left => [
|
363
|
+
create_record(1),
|
364
|
+
create_record(3),
|
365
|
+
create_record(5),
|
366
|
+
],
|
367
|
+
:right => [
|
368
|
+
create_record(2),
|
369
|
+
create_record(4),
|
370
|
+
create_record(6),
|
371
|
+
],
|
372
|
+
:limit => 2,
|
373
|
+
},
|
374
|
+
:string_key_records_with_limit => {
|
375
|
+
:expected => [
|
376
|
+
create_record("a"),
|
377
|
+
create_record("b"),
|
378
|
+
],
|
379
|
+
:left => [
|
380
|
+
create_record("a"),
|
381
|
+
create_record("c"),
|
382
|
+
create_record("e"),
|
383
|
+
],
|
384
|
+
:right => [
|
385
|
+
create_record("b"),
|
386
|
+
create_record("d"),
|
387
|
+
create_record("f"),
|
388
|
+
],
|
389
|
+
:limit => 2,
|
390
|
+
},
|
391
|
+
)
|
392
|
+
def test_sort(data)
|
393
|
+
reduced = reduce_value({
|
394
|
+
"type" => "sort",
|
395
|
+
"operators" => [
|
396
|
+
{ "column" => 0, "operator" => "<" },
|
397
|
+
],
|
398
|
+
"limit" => data[:limit] || -1,
|
399
|
+
},
|
400
|
+
data[:left],
|
401
|
+
data[:right])
|
402
|
+
assert_equal(data[:expected], reduced)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
class MergeRecords < self
|
407
|
+
def test_grouped
|
408
|
+
expected = [
|
409
|
+
[
|
410
|
+
"group3",
|
411
|
+
30,
|
412
|
+
[
|
413
|
+
create_record("A"),
|
414
|
+
create_record("B"),
|
415
|
+
create_record("C"),
|
416
|
+
],
|
417
|
+
],
|
418
|
+
[
|
419
|
+
"group1",
|
420
|
+
40,
|
421
|
+
[
|
422
|
+
create_record(2),
|
423
|
+
create_record(4),
|
424
|
+
create_record(6),
|
425
|
+
create_record(1),
|
426
|
+
create_record(3),
|
427
|
+
create_record(5),
|
428
|
+
],
|
429
|
+
],
|
430
|
+
[
|
431
|
+
"group4",
|
432
|
+
50,
|
433
|
+
[
|
434
|
+
create_record("D"),
|
435
|
+
create_record("E"),
|
436
|
+
create_record("F"),
|
437
|
+
],
|
438
|
+
],
|
439
|
+
[
|
440
|
+
"group2",
|
441
|
+
60,
|
442
|
+
[
|
443
|
+
create_record("b"),
|
444
|
+
create_record("d"),
|
445
|
+
create_record("f"),
|
446
|
+
create_record("a"),
|
447
|
+
create_record("c"),
|
448
|
+
create_record("e"),
|
449
|
+
],
|
450
|
+
],
|
451
|
+
]
|
452
|
+
|
453
|
+
left = [
|
454
|
+
[
|
455
|
+
"group1",
|
456
|
+
10,
|
457
|
+
[
|
458
|
+
create_record(1),
|
459
|
+
create_record(3),
|
460
|
+
create_record(5),
|
461
|
+
],
|
462
|
+
],
|
463
|
+
[
|
464
|
+
"group2",
|
465
|
+
20,
|
466
|
+
[
|
467
|
+
create_record("a"),
|
468
|
+
create_record("c"),
|
469
|
+
create_record("e"),
|
470
|
+
],
|
471
|
+
],
|
472
|
+
[
|
473
|
+
"group3",
|
474
|
+
30,
|
475
|
+
[
|
476
|
+
create_record("A"),
|
477
|
+
create_record("B"),
|
478
|
+
create_record("C"),
|
479
|
+
],
|
480
|
+
],
|
481
|
+
]
|
482
|
+
right = [
|
483
|
+
[
|
484
|
+
"group1",
|
485
|
+
30,
|
486
|
+
[
|
487
|
+
create_record(2),
|
488
|
+
create_record(4),
|
489
|
+
create_record(6),
|
490
|
+
],
|
491
|
+
],
|
492
|
+
[
|
493
|
+
"group2",
|
494
|
+
40,
|
495
|
+
[
|
496
|
+
create_record("b"),
|
497
|
+
create_record("d"),
|
498
|
+
create_record("f"),
|
499
|
+
],
|
500
|
+
],
|
501
|
+
[
|
502
|
+
"group4",
|
503
|
+
50,
|
504
|
+
[
|
505
|
+
create_record("D"),
|
506
|
+
create_record("E"),
|
507
|
+
create_record("F"),
|
508
|
+
],
|
509
|
+
],
|
510
|
+
]
|
511
|
+
|
512
|
+
reduced = reduce_value({
|
513
|
+
"type" => "sort",
|
514
|
+
"operators" => [
|
515
|
+
{ "column" => 1, "operator" => "<" },
|
516
|
+
],
|
517
|
+
"key_column" => 0,
|
518
|
+
"limit" => -1,
|
519
|
+
},
|
520
|
+
left,
|
521
|
+
right)
|
522
|
+
assert_equal(expected, reduced)
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|