fluent-plugin-droonga 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +7 -0
  4. data/benchmark/watch/benchmark-notify.rb +6 -6
  5. data/benchmark/watch/benchmark-notify.sh +3 -2
  6. data/bin/grn2jsons +0 -3
  7. data/doc/text/news.md +13 -0
  8. data/fluent-plugin-droonga.gemspec +1 -1
  9. data/lib/droonga/catalog/base.rb +8 -3
  10. data/lib/droonga/catalog.rb +1 -16
  11. data/lib/droonga/catalog_observer.rb +57 -0
  12. data/lib/droonga/collector.rb +1 -1
  13. data/lib/droonga/dispatcher.rb +3 -1
  14. data/lib/droonga/distributor_plugin.rb +47 -19
  15. data/lib/droonga/handler_messenger.rb +26 -2
  16. data/lib/droonga/message_processing_error.rb +6 -8
  17. data/lib/droonga/output_message.rb +17 -1
  18. data/lib/droonga/plugin/collector/basic.rb +44 -81
  19. data/lib/droonga/plugin/collector/groonga.rb +83 -0
  20. data/lib/droonga/plugin/collector/search.rb +104 -0
  21. data/lib/droonga/plugin/distributor/crud.rb +41 -0
  22. data/lib/droonga/plugin/distributor/distributed_search_planner.rb +4 -4
  23. data/lib/droonga/plugin/distributor/groonga.rb +38 -0
  24. data/lib/droonga/plugin/handler/add.rb +4 -1
  25. data/lib/droonga/plugin/handler/groonga/column_create.rb +7 -0
  26. data/lib/droonga/plugin/handler/groonga/table_remove.rb +42 -0
  27. data/lib/droonga/plugin/handler/groonga.rb +17 -2
  28. data/lib/droonga/plugin/handler/watch.rb +4 -4
  29. data/lib/droonga/plugin/input_adapter/crud.rb +27 -0
  30. data/lib/droonga/plugin/input_adapter/groonga.rb +16 -1
  31. data/lib/droonga/plugin/output_adapter/crud.rb +51 -0
  32. data/lib/droonga/plugin/output_adapter/groonga.rb +8 -1
  33. data/lib/droonga/plugin.rb +1 -1
  34. data/lib/droonga/replier.rb +7 -1
  35. data/lib/droonga/searcher.rb +168 -74
  36. data/lib/droonga/session.rb +1 -1
  37. data/lib/groonga_command_converter.rb +7 -1
  38. data/test/command/config/default/catalog.json +1 -1
  39. data/test/command/suite/add/error/invalid-integer.expected +31 -1
  40. data/test/command/suite/add/error/invalid-time.expected +31 -1
  41. data/test/command/suite/add/error/missing-key.expected +17 -1
  42. data/test/command/suite/add/error/missing-table.expected +17 -1
  43. data/test/command/suite/add/error/unknown-column.expected +31 -1
  44. data/test/command/suite/add/error/unknown-table.expected +17 -1
  45. data/test/command/suite/add/minimum.expected +1 -1
  46. data/test/command/suite/add/with-values.expected +1 -1
  47. data/test/command/suite/add/without-key.expected +1 -1
  48. data/test/command/suite/groonga/column_create/scalar.expected +2 -2
  49. data/test/command/suite/groonga/column_create/unknown-table.expected +18 -0
  50. data/test/command/suite/groonga/column_create/unknown-table.test +7 -0
  51. data/test/command/suite/groonga/column_create/vector.expected +2 -2
  52. data/test/command/suite/groonga/select/minimum.expected +1 -1
  53. data/test/command/suite/groonga/table_create/array.expected +1 -1
  54. data/test/command/suite/groonga/table_create/hash.expected +1 -1
  55. data/test/command/suite/groonga/table_remove/success.expected +17 -0
  56. data/test/command/suite/groonga/table_remove/success.test +8 -0
  57. data/test/command/suite/groonga/table_remove/unknown-table.expected +18 -0
  58. data/test/command/suite/groonga/table_remove/unknown-table.test +7 -0
  59. data/test/command/suite/message/error/missing-dataset.expected +1 -1
  60. data/test/command/suite/message/error/unknown-command.expected +1 -1
  61. data/test/command/suite/message/error/unknown-dataset.expected +1 -1
  62. data/test/command/suite/search/attributes/array.expected +1 -1
  63. data/test/command/suite/search/attributes/hash.expected +1 -1
  64. data/test/command/suite/search/complex.expected +1 -1
  65. data/test/command/suite/search/condition/nested.expected +1 -1
  66. data/test/command/suite/search/condition/query.expected +1 -1
  67. data/test/command/suite/search/condition/script.expected +1 -1
  68. data/test/command/suite/search/error/cyclic-source.expected +1 -1
  69. data/test/command/suite/search/error/deeply-cyclic-source.expected +1 -1
  70. data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
  71. data/test/command/suite/search/error/unknown-source.expected +1 -1
  72. data/test/command/suite/search/group/count.expected +1 -1
  73. data/test/command/suite/search/group/limit.expected +1 -1
  74. data/test/command/suite/search/group/string.expected +1 -1
  75. data/test/command/suite/search/multiple/chained.expected +1 -1
  76. data/test/command/suite/search/multiple/parallel.expected +1 -1
  77. data/test/command/suite/search/range/only-output.expected +1 -1
  78. data/test/command/suite/search/range/only-sort.expected +1 -1
  79. data/test/command/suite/search/range/sort-and-output.expected +1 -1
  80. data/test/command/suite/search/range/too-large-output-offset.expected +1 -1
  81. data/test/command/suite/search/range/too-large-sort-offset.expected +1 -1
  82. data/test/command/suite/search/response/records/value/time.expected +1 -1
  83. data/test/command/suite/search/simple.expected +1 -1
  84. data/test/command/suite/search/sort/default-offset-limit.expected +1 -1
  85. data/test/command/suite/search/sort/invisible-column.expected +1 -1
  86. data/test/command/suite/watch/subscribe.expected +1 -1
  87. data/test/command/suite/watch/unsubscribe.expected +1 -1
  88. data/test/performance/run-test.rb +56 -0
  89. data/{benchmark → test/performance}/watch/catalog.json +0 -0
  90. data/test/performance/watch/feed.json +9 -0
  91. data/{benchmark → test/performance}/watch/fluentd.conf +0 -0
  92. data/test/performance/watch/subscribe.json +3 -0
  93. data/test/unit/catalog/test_version1.rb +34 -0
  94. data/test/unit/plugin/collector/test_basic.rb +300 -479
  95. data/test/unit/plugin/collector/test_search.rb +814 -0
  96. data/test/unit/plugin/distributor/test_search.rb +4 -4
  97. data/test/unit/plugin/distributor/test_search_planner.rb +260 -260
  98. data/test/unit/plugin/handler/groonga/test_column_create.rb +15 -1
  99. data/test/unit/plugin/handler/groonga/test_table_create.rb +6 -2
  100. data/test/unit/plugin/handler/groonga/test_table_remove.rb +58 -0
  101. data/test/unit/plugin/handler/test_add.rb +3 -1
  102. data/test/unit/plugin/handler/test_groonga.rb +24 -0
  103. data/test/unit/plugin/handler/test_search.rb +294 -0
  104. data/test/unit/plugin/handler/test_watch.rb +1 -1
  105. data/test/unit/plugin/{adapter → input_adapter}/groonga/test_select.rb +5 -37
  106. data/test/unit/plugin/output_adapter/groonga/test_select.rb +55 -0
  107. metadata +38 -6
@@ -0,0 +1,814 @@
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/plugin/collector/search"
17
+
18
+ class SearchCollectorTest < Test::Unit::TestCase
19
+ def setup
20
+ setup_database
21
+ @plugin = Droonga::SearchCollector.new
22
+ @outputs = []
23
+ stub(@plugin).emit do |name, value|
24
+ @outputs << [name, value]
25
+ end
26
+ end
27
+
28
+ def teardown
29
+ teardown_database
30
+ end
31
+
32
+ private
33
+ def create_record(*columns)
34
+ columns
35
+ end
36
+
37
+ class << self
38
+ def create_record(*columns)
39
+ columns
40
+ end
41
+ end
42
+
43
+ class GatherTest < self
44
+ data(
45
+ :simple_mapping => {
46
+ :expected => "result",
47
+ :source => "result",
48
+ :mapping => "string_name",
49
+ },
50
+ :complex_mapping => {
51
+ :expected => {
52
+ "count" => 3,
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
+ },
67
+ :mapping => {
68
+ "output" => "search_result",
69
+ },
70
+ },
71
+ :offset_and_limit => {
72
+ :expected => {
73
+ "count" => 3,
74
+ "records" => [
75
+ create_record(1),
76
+ ],
77
+ },
78
+ :source => {
79
+ "count" => 3,
80
+ "records" => [
81
+ create_record(0),
82
+ create_record(1),
83
+ create_record(2),
84
+ ],
85
+ },
86
+ :mapping => {
87
+ "output" => "search_result",
88
+ "elements" => {
89
+ "records" => {
90
+ "type" => "sort",
91
+ "offset" => 1,
92
+ "limit" => 1,
93
+ },
94
+ },
95
+ },
96
+ },
97
+ :offset_and_unlimited_limit => {
98
+ :expected => {
99
+ "count" => 3,
100
+ "records" => [
101
+ create_record(1),
102
+ create_record(2),
103
+ ],
104
+ },
105
+ :source => {
106
+ "count" => 3,
107
+ "records" => [
108
+ create_record(0),
109
+ create_record(1),
110
+ create_record(2),
111
+ ],
112
+ },
113
+ :mapping => {
114
+ "output" => "search_result",
115
+ "elements" => {
116
+ "records" => {
117
+ "type" => "sort",
118
+ "offset" => 1,
119
+ "limit" => -1,
120
+ },
121
+ },
122
+ },
123
+ },
124
+ :too_large_offset => {
125
+ :expected => {
126
+ "count" => 2,
127
+ "records" => [
128
+ ],
129
+ },
130
+ :source => {
131
+ "count" => 2,
132
+ "records" => [
133
+ create_record(1, 1.1, 1.2),
134
+ create_record(2, 2.1, 2.2),
135
+ ],
136
+ },
137
+ :mapping => {
138
+ "output" => "search_result",
139
+ "elements" => {
140
+ "records" => {
141
+ "type" => "sort",
142
+ "format" => "simple",
143
+ "attributes" => [],
144
+ "offset" => 10000,
145
+ "limit" => -1,
146
+ },
147
+ },
148
+ },
149
+ },
150
+ :attributes => {
151
+ :expected => {
152
+ "count" => 2,
153
+ "records" => [
154
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
155
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
156
+ ],
157
+ },
158
+ :source => {
159
+ "count" => 2,
160
+ "records" => [
161
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
162
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
163
+ ],
164
+ },
165
+ :mapping => {
166
+ "output" => "search_result",
167
+ "elements" => {
168
+ "records" => {
169
+ "type" => "sort",
170
+ "attributes" => ["_key", "chapter", "section", "subsection", "paragraph"],
171
+ "limit" => -1,
172
+ },
173
+ },
174
+ },
175
+ },
176
+ :attributes_with_sort_attributes => {
177
+ :expected => {
178
+ "count" => 2,
179
+ "records" => [
180
+ create_record(1, 1.1, 1.2),
181
+ create_record(2, 2.1, 2.2),
182
+ ],
183
+ },
184
+ :source => {
185
+ "count" => 2,
186
+ "records" => [
187
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
188
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
189
+ ],
190
+ },
191
+ :mapping => {
192
+ "output" => "search_result",
193
+ "elements" => {
194
+ "records" => {
195
+ "type" => "sort",
196
+ "attributes" => ["_key", "chapter", "section"],
197
+ "limit" => -1,
198
+ },
199
+ },
200
+ },
201
+ },
202
+ :format_simple => {
203
+ :expected => {
204
+ "count" => 2,
205
+ "records" => [
206
+ create_record(1, 1.1, 1.2),
207
+ create_record(2, 2.1, 2.2),
208
+ ],
209
+ },
210
+ :source => {
211
+ "count" => 2,
212
+ "records" => [
213
+ create_record(1, 1.1, 1.2),
214
+ create_record(2, 2.1, 2.2),
215
+ ],
216
+ },
217
+ :mapping => {
218
+ "output" => "search_result",
219
+ "elements" => {
220
+ "records" => {
221
+ "type" => "sort",
222
+ "format" => "simple",
223
+ "attributes" => ["_key", "chapter", "section"],
224
+ "limit" => -1,
225
+ },
226
+ },
227
+ },
228
+ },
229
+ :format_complex => {
230
+ :expected => {
231
+ "count" => 2,
232
+ "records" => [
233
+ { "_key" => 1, "chapter" => 1.1, "section" => 1.2 },
234
+ { "_key" => 2, "chapter" => 2.1, "section" => 2.2 },
235
+ ],
236
+ },
237
+ :source => {
238
+ "count" => 2,
239
+ "records" => [
240
+ create_record(1, 1.1, 1.2),
241
+ create_record(2, 2.1, 2.2),
242
+ ],
243
+ },
244
+ :mapping => {
245
+ "output" => "search_result",
246
+ "elements" => {
247
+ "records" => {
248
+ "type" => "sort",
249
+ "format" => "complex",
250
+ "attributes" => ["_key", "chapter", "section"],
251
+ "limit" => -1,
252
+ },
253
+ },
254
+ },
255
+ },
256
+ :count_with_records => {
257
+ :expected => {
258
+ "count" => 2,
259
+ "records" => [
260
+ [],
261
+ [],
262
+ ],
263
+ },
264
+ :source => {
265
+ "count" => 5,
266
+ "records" => [
267
+ [],
268
+ [],
269
+ ],
270
+ },
271
+ :mapping => {
272
+ "output" => "search_result",
273
+ "elements" => {
274
+ "count" => {
275
+ "type" => "count",
276
+ "target" => "records",
277
+ },
278
+ "records" => {
279
+ "type" => "sort",
280
+ "format" => "simple",
281
+ "attributes" => [],
282
+ "limit" => -1,
283
+ },
284
+ },
285
+ },
286
+ },
287
+ :count_only => {
288
+ :expected => {
289
+ "count" => 2,
290
+ },
291
+ :source => {
292
+ "count" => 5,
293
+ "records" => [
294
+ [],
295
+ [],
296
+ ],
297
+ },
298
+ :mapping => {
299
+ "output" => "search_result",
300
+ "elements" => {
301
+ "count" => {
302
+ "type" => "count",
303
+ "target" => "records",
304
+ },
305
+ "records" => {
306
+ "type" => "sort",
307
+ "format" => "simple",
308
+ "attributes" => [],
309
+ "limit" => -1,
310
+ "no_output" => true,
311
+ },
312
+ },
313
+ },
314
+ },
315
+ )
316
+ def test_gather(data)
317
+ request = {
318
+ "task" => {
319
+ "values" => nil,
320
+ "component" => {
321
+ "body" => nil,
322
+ "outputs" => nil,
323
+ },
324
+ },
325
+ "id" => nil,
326
+ "value" => data[:source],
327
+ "name" => data[:mapping],
328
+ "descendants" => nil,
329
+ }
330
+ @plugin.process("collector_search_gather", request)
331
+ output_name = data[:mapping]
332
+ output_name = output_name["output"] if output_name.is_a?(Hash)
333
+ assert_equal([output_name, data[:expected]], @outputs.last)
334
+ end
335
+ end
336
+
337
+ class ReduceTest < self
338
+ def test_sum
339
+ input_name = "input_#{Time.now.to_i}"
340
+ output_name = "output_#{Time.now.to_i}"
341
+ request = {
342
+ "task" => {
343
+ "values" => {
344
+ output_name => {
345
+ "numeric_value" => 1,
346
+ "numeric_key_records" => [
347
+ create_record(1),
348
+ create_record(2),
349
+ create_record(3),
350
+ ],
351
+ "string_key_records" => [
352
+ create_record("a"),
353
+ create_record("b"),
354
+ create_record("c"),
355
+ ],
356
+ },
357
+ },
358
+ "component" => {
359
+ "body" => {
360
+ input_name => {
361
+ output_name => {
362
+ "numeric_value" => {
363
+ "type" => "sum",
364
+ "limit" => -1,
365
+ },
366
+ "numeric_key_records" => {
367
+ "type" => "sum",
368
+ "limit" => -1,
369
+ },
370
+ "string_key_records" => {
371
+ "type" => "sum",
372
+ "limit" => -1,
373
+ },
374
+ },
375
+ },
376
+ },
377
+ "outputs" => nil,
378
+ },
379
+ },
380
+ "id" => nil,
381
+ "value" => {
382
+ "numeric_value" => 2,
383
+ "numeric_key_records" => [
384
+ create_record(4),
385
+ create_record(5),
386
+ create_record(6),
387
+ ],
388
+ "string_key_records" => [
389
+ create_record("d"),
390
+ create_record("e"),
391
+ create_record("f"),
392
+ ],
393
+ },
394
+ "name" => input_name,
395
+ "descendants" => nil,
396
+ }
397
+ @plugin.process("collector_search_reduce", request)
398
+ assert_equal([
399
+ output_name,
400
+ {
401
+ "numeric_value" => 3,
402
+ "numeric_key_records" => [
403
+ create_record(1),
404
+ create_record(2),
405
+ create_record(3),
406
+ create_record(4),
407
+ create_record(5),
408
+ create_record(6),
409
+ ],
410
+ "string_key_records" => [
411
+ create_record("a"),
412
+ create_record("b"),
413
+ create_record("c"),
414
+ create_record("d"),
415
+ create_record("e"),
416
+ create_record("f"),
417
+ ],
418
+ },
419
+ ],
420
+ @outputs.last)
421
+ end
422
+
423
+ def test_sum_with_limit
424
+ input_name = "input_#{Time.now.to_i}"
425
+ output_name = "output_#{Time.now.to_i}"
426
+ request = {
427
+ "task" => {
428
+ "values" => {
429
+ output_name => {
430
+ "numeric_value" => 1,
431
+ "numeric_key_records" => [
432
+ create_record(1),
433
+ create_record(2),
434
+ create_record(3),
435
+ ],
436
+ "string_key_records" => [
437
+ create_record("a"),
438
+ create_record("b"),
439
+ create_record("c"),
440
+ ],
441
+ },
442
+ },
443
+ "component" => {
444
+ "body" => {
445
+ input_name => {
446
+ output_name => {
447
+ "numeric_value" => {
448
+ "type" => "sum",
449
+ "limit" => 2,
450
+ },
451
+ "numeric_key_records" => {
452
+ "type" => "sum",
453
+ "limit" => 2,
454
+ },
455
+ "string_key_records" => {
456
+ "type" => "sum",
457
+ "limit" => -1,
458
+ },
459
+ },
460
+ },
461
+ },
462
+ "outputs" => nil,
463
+ },
464
+ },
465
+ "id" => nil,
466
+ "value" => {
467
+ "numeric_value" => 2,
468
+ "numeric_key_records" => [
469
+ create_record(4),
470
+ create_record(5),
471
+ create_record(6),
472
+ ],
473
+ "string_key_records" => [
474
+ create_record("d"),
475
+ create_record("e"),
476
+ create_record("f"),
477
+ ],
478
+ },
479
+ "name" => input_name,
480
+ "descendants" => nil,
481
+ }
482
+ @plugin.process("collector_search_reduce", request)
483
+ assert_equal([
484
+ output_name,
485
+ {
486
+ "numeric_value" => 3,
487
+ "numeric_key_records" => [
488
+ create_record(1),
489
+ create_record(2),
490
+ ],
491
+ "string_key_records" => [
492
+ create_record("a"),
493
+ create_record("b"),
494
+ create_record("c"),
495
+ create_record("d"),
496
+ create_record("e"),
497
+ create_record("f"),
498
+ ],
499
+ },
500
+ ],
501
+ @outputs.last)
502
+ end
503
+
504
+ def test_sort
505
+ input_name = "input_#{Time.now.to_i}"
506
+ output_name = "output_#{Time.now.to_i}"
507
+ request = {
508
+ "task" => {
509
+ "values" => {
510
+ output_name => {
511
+ "numeric_key_records" => [
512
+ create_record(1),
513
+ create_record(3),
514
+ create_record(5),
515
+ ],
516
+ "string_key_records" => [
517
+ create_record("a"),
518
+ create_record("c"),
519
+ create_record("e"),
520
+ ],
521
+ },
522
+ },
523
+ "component" => {
524
+ "body" => {
525
+ input_name => {
526
+ output_name => {
527
+ "numeric_key_records" => {
528
+ "type" => "sort",
529
+ "operators" => [
530
+ { "column" => 0, "operator" => "<" },
531
+ ],
532
+ "limit" => -1,
533
+ },
534
+ "string_key_records" => {
535
+ "type" => "sort",
536
+ "operators" => [
537
+ { "column" => 0, "operator" => "<" },
538
+ ],
539
+ "limit" => -1,
540
+ },
541
+ },
542
+ },
543
+ },
544
+ "outputs" => nil,
545
+ },
546
+ },
547
+ "id" => nil,
548
+ "value" => {
549
+ "numeric_key_records" => [
550
+ create_record(2),
551
+ create_record(4),
552
+ create_record(6),
553
+ ],
554
+ "string_key_records" => [
555
+ create_record("b"),
556
+ create_record("d"),
557
+ create_record("f"),
558
+ ],
559
+ },
560
+ "name" => input_name,
561
+ "descendants" => nil,
562
+ }
563
+ @plugin.process("collector_search_reduce", request)
564
+ assert_equal([
565
+ output_name,
566
+ {
567
+ "numeric_key_records" => [
568
+ create_record(1),
569
+ create_record(2),
570
+ create_record(3),
571
+ create_record(4),
572
+ create_record(5),
573
+ create_record(6),
574
+ ],
575
+ "string_key_records" => [
576
+ create_record("a"),
577
+ create_record("b"),
578
+ create_record("c"),
579
+ create_record("d"),
580
+ create_record("e"),
581
+ create_record("f"),
582
+ ],
583
+ },
584
+ ],
585
+ @outputs.last)
586
+ end
587
+
588
+ def test_sort_with_limit
589
+ input_name = "input_#{Time.now.to_i}"
590
+ output_name = "output_#{Time.now.to_i}"
591
+ request = {
592
+ "task" => {
593
+ "values" => {
594
+ output_name => {
595
+ "numeric_key_records" => [
596
+ create_record(1),
597
+ create_record(3),
598
+ create_record(5),
599
+ ],
600
+ "string_key_records" => [
601
+ create_record("a"),
602
+ create_record("c"),
603
+ create_record("e"),
604
+ ],
605
+ },
606
+ },
607
+ "component" => {
608
+ "body" => {
609
+ input_name => {
610
+ output_name => {
611
+ "numeric_key_records" => {
612
+ "type" => "sort",
613
+ "operators" => [
614
+ { "column" => 0, "operator" => "<" },
615
+ ],
616
+ "limit" => 2,
617
+ },
618
+ "string_key_records" => {
619
+ "type" => "sort",
620
+ "operators" => [
621
+ { "column" => 0, "operator" => "<" },
622
+ ],
623
+ "limit" => -1,
624
+ },
625
+ },
626
+ },
627
+ },
628
+ "outputs" => nil,
629
+ },
630
+ },
631
+ "id" => nil,
632
+ "value" => {
633
+ "numeric_key_records" => [
634
+ create_record(2),
635
+ create_record(4),
636
+ create_record(6),
637
+ ],
638
+ "string_key_records" => [
639
+ create_record("b"),
640
+ create_record("d"),
641
+ create_record("f"),
642
+ ],
643
+ },
644
+ "name" => input_name,
645
+ "descendants" => nil,
646
+ }
647
+ @plugin.process("collector_search_reduce", request)
648
+ assert_equal([
649
+ output_name,
650
+ {
651
+ "numeric_key_records" => [
652
+ create_record(1),
653
+ create_record(2),
654
+ ],
655
+ "string_key_records" => [
656
+ create_record("a"),
657
+ create_record("b"),
658
+ create_record("c"),
659
+ create_record("d"),
660
+ create_record("e"),
661
+ create_record("f"),
662
+ ],
663
+ },
664
+ ],
665
+ @outputs.last)
666
+ end
667
+ end
668
+
669
+ class MergeTest < self
670
+ def test_grouped
671
+ input_name = "input_#{Time.now.to_i}"
672
+ output_name = "output_#{Time.now.to_i}"
673
+ request = {
674
+ "task" => {
675
+ "values" => {
676
+ output_name => {
677
+ "records" => [
678
+ [
679
+ "group1",
680
+ 10,
681
+ [
682
+ create_record(1),
683
+ create_record(3),
684
+ create_record(5),
685
+ ],
686
+ ],
687
+ [
688
+ "group2",
689
+ 20,
690
+ [
691
+ create_record("a"),
692
+ create_record("c"),
693
+ create_record("e"),
694
+ ],
695
+ ],
696
+ [
697
+ "group3",
698
+ 30,
699
+ [
700
+ create_record("A"),
701
+ create_record("B"),
702
+ create_record("C"),
703
+ ],
704
+ ],
705
+ ],
706
+ },
707
+ },
708
+ "component" => {
709
+ "body" => {
710
+ input_name => {
711
+ output_name => {
712
+ "records" => {
713
+ "type" => "sort",
714
+ "operators" => [
715
+ { "column" => 1, "operator" => "<" },
716
+ ],
717
+ "key_column" => 0,
718
+ "limit" => -1,
719
+ },
720
+ },
721
+ },
722
+ },
723
+ "outputs" => nil,
724
+ },
725
+ },
726
+ "id" => nil,
727
+ "value" => {
728
+ "records" => [
729
+ [
730
+ "group1",
731
+ 30,
732
+ [
733
+ create_record(2),
734
+ create_record(4),
735
+ create_record(6),
736
+ ],
737
+ ],
738
+ [
739
+ "group2",
740
+ 40,
741
+ [
742
+ create_record("b"),
743
+ create_record("d"),
744
+ create_record("f"),
745
+ ],
746
+ ],
747
+ [
748
+ "group4",
749
+ 50,
750
+ [
751
+ create_record("D"),
752
+ create_record("E"),
753
+ create_record("F"),
754
+ ],
755
+ ],
756
+ ],
757
+ },
758
+ "name" => input_name,
759
+ "descendants" => nil,
760
+ }
761
+ @plugin.process("collector_search_reduce", request)
762
+ assert_equal([
763
+ output_name,
764
+ {
765
+ "records" => [
766
+ [
767
+ "group3",
768
+ 30,
769
+ [
770
+ create_record("A"),
771
+ create_record("B"),
772
+ create_record("C"),
773
+ ],
774
+ ],
775
+ [
776
+ "group1",
777
+ 40,
778
+ [
779
+ create_record(2),
780
+ create_record(4),
781
+ create_record(6),
782
+ create_record(1),
783
+ create_record(3),
784
+ create_record(5),
785
+ ],
786
+ ],
787
+ [
788
+ "group4",
789
+ 50,
790
+ [
791
+ create_record("D"),
792
+ create_record("E"),
793
+ create_record("F"),
794
+ ],
795
+ ],
796
+ [
797
+ "group2",
798
+ 60,
799
+ [
800
+ create_record("b"),
801
+ create_record("d"),
802
+ create_record("f"),
803
+ create_record("a"),
804
+ create_record("c"),
805
+ create_record("e"),
806
+ ],
807
+ ],
808
+ ],
809
+ },
810
+ ],
811
+ @outputs.last)
812
+ end
813
+ end
814
+ end