droonga-engine 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (341) hide show
  1. data/.dir-locals.el +3 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +7 -0
  5. data/Gemfile +66 -0
  6. data/LICENSE.txt +14 -0
  7. data/README.md +17 -0
  8. data/Rakefile +64 -0
  9. data/benchmark/benchmark.rb +123 -0
  10. data/benchmark/utils.rb +246 -0
  11. data/benchmark/watch/benchmark-notify.rb +143 -0
  12. data/benchmark/watch/benchmark-notify.sh +20 -0
  13. data/benchmark/watch/benchmark-publish.rb +120 -0
  14. data/benchmark/watch/benchmark-scan.rb +213 -0
  15. data/bin/droonga-catalog-generate +103 -0
  16. data/bin/droonga-engine +20 -0
  17. data/bin/droonga-engine-service +20 -0
  18. data/doc/text/news.md +106 -0
  19. data/droonga-engine.gemspec +52 -0
  20. data/lib/droonga/adapter.rb +48 -0
  21. data/lib/droonga/adapter_runner.rb +104 -0
  22. data/lib/droonga/catalog/base.rb +41 -0
  23. data/lib/droonga/catalog/collection_volume.rb +106 -0
  24. data/lib/droonga/catalog/dataset.rb +69 -0
  25. data/lib/droonga/catalog/errors.rb +113 -0
  26. data/lib/droonga/catalog/schema.rb +186 -0
  27. data/lib/droonga/catalog/single_volume.rb +28 -0
  28. data/lib/droonga/catalog/slice.rb +41 -0
  29. data/lib/droonga/catalog/version1.rb +427 -0
  30. data/lib/droonga/catalog/version2.rb +96 -0
  31. data/lib/droonga/catalog/version2_validator.rb +63 -0
  32. data/lib/droonga/catalog/volume.rb +33 -0
  33. data/lib/droonga/catalog/volume_collection.rb +56 -0
  34. data/lib/droonga/catalog_generator.rb +156 -0
  35. data/lib/droonga/catalog_loader.rb +56 -0
  36. data/lib/droonga/catalog_observer.rb +83 -0
  37. data/lib/droonga/collector.rb +38 -0
  38. data/lib/droonga/collector_message.rb +71 -0
  39. data/lib/droonga/collector_runner.rb +64 -0
  40. data/lib/droonga/collectors/and.rb +26 -0
  41. data/lib/droonga/collectors/or.rb +26 -0
  42. data/lib/droonga/collectors/sum.rb +26 -0
  43. data/lib/droonga/collectors.rb +18 -0
  44. data/lib/droonga/dispatcher.rb +326 -0
  45. data/lib/droonga/distributed_command_planner.rb +179 -0
  46. data/lib/droonga/distributor.rb +87 -0
  47. data/lib/droonga/engine/command/droonga_engine.rb +441 -0
  48. data/lib/droonga/engine/version.rb +20 -0
  49. data/lib/droonga/engine.rb +80 -0
  50. data/lib/droonga/engine_state.rb +79 -0
  51. data/lib/droonga/error.rb +73 -0
  52. data/lib/droonga/error_messages.rb +33 -0
  53. data/lib/droonga/event_loop.rb +46 -0
  54. data/lib/droonga/farm.rb +58 -0
  55. data/lib/droonga/fluent_message_receiver.rb +191 -0
  56. data/lib/droonga/fluent_message_sender.rb +140 -0
  57. data/lib/droonga/forwarder.rb +119 -0
  58. data/lib/droonga/handler.rb +49 -0
  59. data/lib/droonga/handler_message.rb +61 -0
  60. data/lib/droonga/handler_messenger.rb +119 -0
  61. data/lib/droonga/handler_runner.rb +125 -0
  62. data/lib/droonga/input_message.rb +51 -0
  63. data/lib/droonga/job_protocol.rb +20 -0
  64. data/lib/droonga/job_pusher.rb +179 -0
  65. data/lib/droonga/job_receiver.rb +70 -0
  66. data/lib/droonga/loggable.rb +29 -0
  67. data/lib/droonga/logger.rb +142 -0
  68. data/lib/droonga/message_matcher.rb +109 -0
  69. data/lib/droonga/output_message.rb +55 -0
  70. data/lib/droonga/planner.rb +47 -0
  71. data/lib/droonga/pluggable.rb +31 -0
  72. data/lib/droonga/plugin/metadata/adapter_input_message.rb +39 -0
  73. data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
  74. data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
  75. data/lib/droonga/plugin/metadata/handler_action.rb +39 -0
  76. data/lib/droonga/plugin/metadata/input_message.rb +54 -0
  77. data/lib/droonga/plugin.rb +43 -0
  78. data/lib/droonga/plugin_loader.rb +63 -0
  79. data/lib/droonga/plugin_registry.rb +66 -0
  80. data/lib/droonga/plugins/basic.rb +54 -0
  81. data/lib/droonga/plugins/crud.rb +145 -0
  82. data/lib/droonga/plugins/dump.rb +97 -0
  83. data/lib/droonga/plugins/error.rb +51 -0
  84. data/lib/droonga/plugins/groonga/column_create.rb +123 -0
  85. data/lib/droonga/plugins/groonga/column_list.rb +124 -0
  86. data/lib/droonga/plugins/groonga/column_remove.rb +65 -0
  87. data/lib/droonga/plugins/groonga/column_rename.rb +67 -0
  88. data/lib/droonga/plugins/groonga/delete.rb +117 -0
  89. data/lib/droonga/plugins/groonga/generic_command.rb +105 -0
  90. data/lib/droonga/plugins/groonga/generic_response.rb +43 -0
  91. data/lib/droonga/plugins/groonga/select.rb +236 -0
  92. data/lib/droonga/plugins/groonga/table_create.rb +111 -0
  93. data/lib/droonga/plugins/groonga/table_list.rb +120 -0
  94. data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
  95. data/lib/droonga/plugins/groonga.rb +37 -0
  96. data/lib/droonga/plugins/search/distributed_search_planner.rb +407 -0
  97. data/lib/droonga/plugins/search.rb +146 -0
  98. data/lib/droonga/plugins/watch.rb +178 -0
  99. data/lib/droonga/processor.rb +63 -0
  100. data/lib/droonga/reducer.rb +169 -0
  101. data/lib/droonga/replier.rb +49 -0
  102. data/lib/droonga/schema_applier.rb +167 -0
  103. data/lib/droonga/searcher/mecab_filter.rb +67 -0
  104. data/lib/droonga/searcher.rb +733 -0
  105. data/lib/droonga/server.rb +45 -0
  106. data/lib/droonga/session.rb +99 -0
  107. data/lib/droonga/single_step.rb +68 -0
  108. data/lib/droonga/single_step_definition.rb +54 -0
  109. data/lib/droonga/slice.rb +122 -0
  110. data/lib/droonga/status_code.rb +25 -0
  111. data/lib/droonga/step_runner.rb +64 -0
  112. data/lib/droonga/sweeper.rb +42 -0
  113. data/lib/droonga/test/stub_handler.rb +37 -0
  114. data/lib/droonga/test/stub_handler_message.rb +35 -0
  115. data/lib/droonga/test/stub_handler_messenger.rb +34 -0
  116. data/lib/droonga/test/stub_planner.rb +31 -0
  117. data/lib/droonga/test.rb +21 -0
  118. data/lib/droonga/watch_schema.rb +92 -0
  119. data/lib/droonga/watcher.rb +257 -0
  120. data/lib/droonga/worker.rb +61 -0
  121. data/sample/cluster/catalog.json +42 -0
  122. data/sample/mecab_filter/data.grn +7 -0
  123. data/sample/mecab_filter/ddl.grn +7 -0
  124. data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
  125. data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
  126. data/test/command/config/default/catalog.json +85 -0
  127. data/test/command/config/default/fluentd.conf +11 -0
  128. data/test/command/config/version1/catalog.json +68 -0
  129. data/test/command/config/version1/fluentd.conf +11 -0
  130. data/test/command/fixture/documents.jsons +208 -0
  131. data/test/command/fixture/event.jsons +41 -0
  132. data/test/command/fixture/user-table-array.jsons +38 -0
  133. data/test/command/fixture/user-table.jsons +47 -0
  134. data/test/command/run-test.rb +34 -0
  135. data/test/command/suite/add/dimension/column.catalog.json +28 -0
  136. data/test/command/suite/add/dimension/column.expected +41 -0
  137. data/test/command/suite/add/dimension/column.test +51 -0
  138. data/test/command/suite/add/dimension/integer.catalog.json +19 -0
  139. data/test/command/suite/add/dimension/integer.expected +41 -0
  140. data/test/command/suite/add/dimension/integer.test +51 -0
  141. data/test/command/suite/add/error/invalid-integer.expected +46 -0
  142. data/test/command/suite/add/error/invalid-integer.test +12 -0
  143. data/test/command/suite/add/error/invalid-time.expected +46 -0
  144. data/test/command/suite/add/error/invalid-time.test +12 -0
  145. data/test/command/suite/add/error/missing-key.expected +25 -0
  146. data/test/command/suite/add/error/missing-key.test +16 -0
  147. data/test/command/suite/add/error/missing-table.expected +25 -0
  148. data/test/command/suite/add/error/missing-table.test +16 -0
  149. data/test/command/suite/add/error/unknown-column.expected +46 -0
  150. data/test/command/suite/add/error/unknown-column.test +12 -0
  151. data/test/command/suite/add/error/unknown-table.expected +25 -0
  152. data/test/command/suite/add/error/unknown-table.test +17 -0
  153. data/test/command/suite/add/minimum.expected +6 -0
  154. data/test/command/suite/add/minimum.test +11 -0
  155. data/test/command/suite/add/with-values.expected +6 -0
  156. data/test/command/suite/add/with-values.test +17 -0
  157. data/test/command/suite/add/without-key.expected +6 -0
  158. data/test/command/suite/add/without-key.test +16 -0
  159. data/test/command/suite/groonga/column_create/scalar.expected +26 -0
  160. data/test/command/suite/groonga/column_create/scalar.test +17 -0
  161. data/test/command/suite/groonga/column_create/unknown-table.expected +14 -0
  162. data/test/command/suite/groonga/column_create/unknown-table.test +7 -0
  163. data/test/command/suite/groonga/column_create/vector.expected +26 -0
  164. data/test/command/suite/groonga/column_create/vector.test +18 -0
  165. data/test/command/suite/groonga/column_list/success.expected +86 -0
  166. data/test/command/suite/groonga/column_list/success.test +24 -0
  167. data/test/command/suite/groonga/column_list/unknown-table.expected +13 -0
  168. data/test/command/suite/groonga/column_list/unknown-table.test +7 -0
  169. data/test/command/suite/groonga/column_remove/success.expected +39 -0
  170. data/test/command/suite/groonga/column_remove/success.test +25 -0
  171. data/test/command/suite/groonga/column_remove/unknown-column.expected +27 -0
  172. data/test/command/suite/groonga/column_remove/unknown-column.test +16 -0
  173. data/test/command/suite/groonga/column_remove/unknown-table.expected +14 -0
  174. data/test/command/suite/groonga/column_remove/unknown-table.test +7 -0
  175. data/test/command/suite/groonga/column_rename/success.expected +39 -0
  176. data/test/command/suite/groonga/column_rename/success.test +26 -0
  177. data/test/command/suite/groonga/column_rename/unknown-column.expected +27 -0
  178. data/test/command/suite/groonga/column_rename/unknown-column.test +16 -0
  179. data/test/command/suite/groonga/column_rename/unknown-table.expected +14 -0
  180. data/test/command/suite/groonga/column_rename/unknown-table.test +7 -0
  181. data/test/command/suite/groonga/delete/duplicated-identifiers.expected +27 -0
  182. data/test/command/suite/groonga/delete/duplicated-identifiers.test +17 -0
  183. data/test/command/suite/groonga/delete/filter.expected +19 -0
  184. data/test/command/suite/groonga/delete/filter.test +19 -0
  185. data/test/command/suite/groonga/delete/invalid-filter.expected +14 -0
  186. data/test/command/suite/groonga/delete/invalid-filter.test +9 -0
  187. data/test/command/suite/groonga/delete/no-identifier.expected +27 -0
  188. data/test/command/suite/groonga/delete/no-identifier.test +15 -0
  189. data/test/command/suite/groonga/delete/success.expected +19 -0
  190. data/test/command/suite/groonga/delete/success.test +19 -0
  191. data/test/command/suite/groonga/delete/unknown-table.expected +14 -0
  192. data/test/command/suite/groonga/delete/unknown-table.test +7 -0
  193. data/test/command/suite/groonga/select/minimum.expected +22 -0
  194. data/test/command/suite/groonga/select/minimum.test +8 -0
  195. data/test/command/suite/groonga/table_create/array.expected +14 -0
  196. data/test/command/suite/groonga/table_create/array.test +8 -0
  197. data/test/command/suite/groonga/table_create/hash.expected +13 -0
  198. data/test/command/suite/groonga/table_create/hash.test +8 -0
  199. data/test/command/suite/groonga/table_list/success.expected +71 -0
  200. data/test/command/suite/groonga/table_list/success.test +15 -0
  201. data/test/command/suite/groonga/table_remove/success.expected +13 -0
  202. data/test/command/suite/groonga/table_remove/success.test +8 -0
  203. data/test/command/suite/groonga/table_remove/unknown-table.expected +14 -0
  204. data/test/command/suite/groonga/table_remove/unknown-table.test +7 -0
  205. data/test/command/suite/message/error/missing-dataset.expected +9 -0
  206. data/test/command/suite/message/error/missing-dataset.test +5 -0
  207. data/test/command/suite/message/error/unknown-dataset.expected +9 -0
  208. data/test/command/suite/message/error/unknown-dataset.test +6 -0
  209. data/test/command/suite/message/error/unknown-type.expected +9 -0
  210. data/test/command/suite/message/error/unknown-type.test +6 -0
  211. data/test/command/suite/search/adjusters/multiple.catalog.json +38 -0
  212. data/test/command/suite/search/adjusters/multiple.expected +19 -0
  213. data/test/command/suite/search/adjusters/multiple.test +75 -0
  214. data/test/command/suite/search/adjusters/one.catalog.json +38 -0
  215. data/test/command/suite/search/adjusters/one.expected +19 -0
  216. data/test/command/suite/search/adjusters/one.test +66 -0
  217. data/test/command/suite/search/attributes/array.expected +21 -0
  218. data/test/command/suite/search/attributes/array.test +28 -0
  219. data/test/command/suite/search/attributes/hash.expected +30 -0
  220. data/test/command/suite/search/attributes/hash.test +36 -0
  221. data/test/command/suite/search/complex.expected +48 -0
  222. data/test/command/suite/search/complex.test +23 -0
  223. data/test/command/suite/search/condition/nested.expected +15 -0
  224. data/test/command/suite/search/condition/nested.test +27 -0
  225. data/test/command/suite/search/condition/query/nonexistent_column.catalog.json +37 -0
  226. data/test/command/suite/search/condition/query/nonexistent_column.expected +48 -0
  227. data/test/command/suite/search/condition/query/nonexistent_column.test +33 -0
  228. data/test/command/suite/search/condition/query/syntax_error.catalog.json +36 -0
  229. data/test/command/suite/search/condition/query/syntax_error.expected +48 -0
  230. data/test/command/suite/search/condition/query/syntax_error.test +33 -0
  231. data/test/command/suite/search/condition/query.expected +24 -0
  232. data/test/command/suite/search/condition/query.test +23 -0
  233. data/test/command/suite/search/condition/script.expected +24 -0
  234. data/test/command/suite/search/condition/script.test +26 -0
  235. data/test/command/suite/search/error/cyclic-source.expected +14 -0
  236. data/test/command/suite/search/error/cyclic-source.test +12 -0
  237. data/test/command/suite/search/error/deeply-cyclic-source.expected +17 -0
  238. data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
  239. data/test/command/suite/search/error/missing-source-parameter.expected +13 -0
  240. data/test/command/suite/search/error/missing-source-parameter.test +11 -0
  241. data/test/command/suite/search/error/no-query.expected +9 -0
  242. data/test/command/suite/search/error/no-query.test +7 -0
  243. data/test/command/suite/search/error/unknown-source.expected +52 -0
  244. data/test/command/suite/search/error/unknown-source.test +12 -0
  245. data/test/command/suite/search/group/count.expected +10 -0
  246. data/test/command/suite/search/group/count.test +18 -0
  247. data/test/command/suite/search/group/limit.expected +15 -0
  248. data/test/command/suite/search/group/limit.test +20 -0
  249. data/test/command/suite/search/group/string.expected +32 -0
  250. data/test/command/suite/search/group/string.test +40 -0
  251. data/test/command/suite/search/group/subrecord/with-sort.catalog.json +33 -0
  252. data/test/command/suite/search/group/subrecord/with-sort.expected +30 -0
  253. data/test/command/suite/search/group/subrecord/with-sort.test +81 -0
  254. data/test/command/suite/search/multiple/chained.expected +41 -0
  255. data/test/command/suite/search/multiple/chained.test +39 -0
  256. data/test/command/suite/search/multiple/parallel.expected +35 -0
  257. data/test/command/suite/search/multiple/parallel.test +35 -0
  258. data/test/command/suite/search/output/attributes/invalid.catalog.json +13 -0
  259. data/test/command/suite/search/output/attributes/invalid.expected +44 -0
  260. data/test/command/suite/search/output/attributes/invalid.test +28 -0
  261. data/test/command/suite/search/range/only-output.expected +24 -0
  262. data/test/command/suite/search/range/only-output.test +23 -0
  263. data/test/command/suite/search/range/only-sort.expected +24 -0
  264. data/test/command/suite/search/range/only-sort.test +26 -0
  265. data/test/command/suite/search/range/sort-and-output.expected +21 -0
  266. data/test/command/suite/search/range/sort-and-output.test +27 -0
  267. data/test/command/suite/search/range/too-large-output-offset.expected +12 -0
  268. data/test/command/suite/search/range/too-large-output-offset.test +23 -0
  269. data/test/command/suite/search/range/too-large-sort-offset.expected +12 -0
  270. data/test/command/suite/search/range/too-large-sort-offset.test +26 -0
  271. data/test/command/suite/search/response/elapsed_time.catalog.json +13 -0
  272. data/test/command/suite/search/response/elapsed_time.expected +11 -0
  273. data/test/command/suite/search/response/elapsed_time.test +26 -0
  274. data/test/command/suite/search/response/records/value/time.expected +20 -0
  275. data/test/command/suite/search/response/records/value/time.test +22 -0
  276. data/test/command/suite/search/simple.expected +48 -0
  277. data/test/command/suite/search/simple.test +22 -0
  278. data/test/command/suite/search/sort/default-offset-limit.expected +39 -0
  279. data/test/command/suite/search/sort/default-offset-limit.test +24 -0
  280. data/test/command/suite/search/sort/invisible-column.expected +24 -0
  281. data/test/command/suite/search/sort/invisible-column.test +26 -0
  282. data/test/command/suite/watch/subscribe.expected +6 -0
  283. data/test/command/suite/watch/subscribe.test +9 -0
  284. data/test/command/suite/watch/unsubscribe.expected +6 -0
  285. data/test/command/suite/watch/unsubscribe.test +9 -0
  286. data/test/performance/run-test.rb +56 -0
  287. data/test/performance/watch/catalog.json +33 -0
  288. data/test/performance/watch/feed.json +9 -0
  289. data/test/performance/watch/fluentd.conf +11 -0
  290. data/test/performance/watch/subscribe.json +3 -0
  291. data/test/unit/catalog/test_collection_volume.rb +103 -0
  292. data/test/unit/catalog/test_dataset.rb +104 -0
  293. data/test/unit/catalog/test_schema.rb +226 -0
  294. data/test/unit/catalog/test_single_volume.rb +31 -0
  295. data/test/unit/catalog/test_slice.rb +92 -0
  296. data/test/unit/catalog/test_version1.rb +361 -0
  297. data/test/unit/catalog/test_version2.rb +124 -0
  298. data/test/unit/catalog/test_version2_validator.rb +66 -0
  299. data/test/unit/catalog/test_volume_collection.rb +50 -0
  300. data/test/unit/fixtures/array.grn +18 -0
  301. data/test/unit/fixtures/catalog/version1.json +40 -0
  302. data/test/unit/fixtures/catalog/version2.json +62 -0
  303. data/test/unit/fixtures/document.grn +34 -0
  304. data/test/unit/fixtures/reference/array.grn +11 -0
  305. data/test/unit/fixtures/reference/hash.grn +7 -0
  306. data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
  307. data/test/unit/helper/fixture.rb +28 -0
  308. data/test/unit/helper/plugin_helper.rb +38 -0
  309. data/test/unit/helper/sandbox.rb +86 -0
  310. data/test/unit/helper/stub_worker.rb +27 -0
  311. data/test/unit/helper/watch_helper.rb +23 -0
  312. data/test/unit/helper.rb +28 -0
  313. data/test/unit/plugins/crud/test_add.rb +190 -0
  314. data/test/unit/plugins/groonga/select/test_adapter_input.rb +510 -0
  315. data/test/unit/plugins/groonga/select/test_adapter_output.rb +201 -0
  316. data/test/unit/plugins/groonga/test_column_create.rb +171 -0
  317. data/test/unit/plugins/groonga/test_column_list.rb +170 -0
  318. data/test/unit/plugins/groonga/test_column_remove.rb +98 -0
  319. data/test/unit/plugins/groonga/test_column_rename.rb +105 -0
  320. data/test/unit/plugins/groonga/test_delete.rb +127 -0
  321. data/test/unit/plugins/groonga/test_table_create.rb +147 -0
  322. data/test/unit/plugins/groonga/test_table_list.rb +184 -0
  323. data/test/unit/plugins/groonga/test_table_remove.rb +61 -0
  324. data/test/unit/plugins/search/planner/test_basic.rb +120 -0
  325. data/test/unit/plugins/search/planner/test_group_by.rb +573 -0
  326. data/test/unit/plugins/search/planner/test_output.rb +388 -0
  327. data/test/unit/plugins/search/planner/test_sort_by.rb +938 -0
  328. data/test/unit/plugins/search/test_collector.rb +806 -0
  329. data/test/unit/plugins/search/test_handler.rb +930 -0
  330. data/test/unit/plugins/search/test_planner.rb +174 -0
  331. data/test/unit/plugins/test_basic.rb +510 -0
  332. data/test/unit/plugins/test_groonga.rb +70 -0
  333. data/test/unit/plugins/test_watch.rb +211 -0
  334. data/test/unit/run-test.rb +56 -0
  335. data/test/unit/test_catalog_generator.rb +93 -0
  336. data/test/unit/test_message_matcher.rb +160 -0
  337. data/test/unit/test_schema_applier.rb +59 -0
  338. data/test/unit/test_sweeper.rb +95 -0
  339. data/test/unit/test_watch_schema.rb +57 -0
  340. data/test/unit/test_watcher.rb +336 -0
  341. metadata +759 -0
@@ -0,0 +1,806 @@
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/plugins/search"
17
+
18
+ class SearchCollectorTest < Test::Unit::TestCase
19
+ def setup
20
+ setup_database
21
+ end
22
+
23
+ def teardown
24
+ teardown_database
25
+ end
26
+
27
+ private
28
+ def create_record(*columns)
29
+ columns
30
+ end
31
+
32
+ def run_collector(collector, message)
33
+ collector_message = Droonga::CollectorMessage.new(message)
34
+ collector.collect(collector_message)
35
+ collector_message.values
36
+ end
37
+
38
+ def gather(message)
39
+ collector = Droonga::Plugins::Search::GatherCollector.new
40
+ run_collector(collector, message)
41
+ end
42
+
43
+ def reduce(message)
44
+ collector = Droonga::Plugins::Search::ReduceCollector.new
45
+ run_collector(collector, message)
46
+ end
47
+
48
+ class << self
49
+ def create_record(*columns)
50
+ columns
51
+ end
52
+ end
53
+
54
+ class GatherTest < self
55
+ data(
56
+ :simple_mapping => {
57
+ :expected => "result",
58
+ :source => "result",
59
+ :mapping => "string_name",
60
+ },
61
+ :complex_mapping => {
62
+ :expected => {
63
+ "count" => 3,
64
+ "records" => [
65
+ create_record(0),
66
+ create_record(1),
67
+ create_record(2),
68
+ ],
69
+ },
70
+ :source => {
71
+ "count" => 3,
72
+ "records" => [
73
+ create_record(0),
74
+ create_record(1),
75
+ create_record(2),
76
+ ],
77
+ },
78
+ :mapping => {
79
+ "output" => "search_result",
80
+ },
81
+ },
82
+ :offset_and_limit => {
83
+ :expected => {
84
+ "count" => 3,
85
+ "records" => [
86
+ create_record(1),
87
+ ],
88
+ },
89
+ :source => {
90
+ "count" => 3,
91
+ "records" => [
92
+ create_record(0),
93
+ create_record(1),
94
+ create_record(2),
95
+ ],
96
+ },
97
+ :mapping => {
98
+ "output" => "search_result",
99
+ "elements" => {
100
+ "records" => {
101
+ "attributes" => ["_key"],
102
+ "offset" => 1,
103
+ "limit" => 1,
104
+ },
105
+ },
106
+ },
107
+ },
108
+ :offset_and_unlimited_limit => {
109
+ :expected => {
110
+ "count" => 3,
111
+ "records" => [
112
+ create_record(1),
113
+ create_record(2),
114
+ ],
115
+ },
116
+ :source => {
117
+ "count" => 3,
118
+ "records" => [
119
+ create_record(0),
120
+ create_record(1),
121
+ create_record(2),
122
+ ],
123
+ },
124
+ :mapping => {
125
+ "output" => "search_result",
126
+ "elements" => {
127
+ "records" => {
128
+ "attributes" => ["_key"],
129
+ "offset" => 1,
130
+ "limit" => -1,
131
+ },
132
+ },
133
+ },
134
+ },
135
+ :too_large_offset => {
136
+ :expected => {
137
+ "count" => 2,
138
+ "records" => [
139
+ ],
140
+ },
141
+ :source => {
142
+ "count" => 2,
143
+ "records" => [
144
+ create_record(1, 1.1, 1.2),
145
+ create_record(2, 2.1, 2.2),
146
+ ],
147
+ },
148
+ :mapping => {
149
+ "output" => "search_result",
150
+ "elements" => {
151
+ "records" => {
152
+ "format" => "simple",
153
+ "attributes" => [],
154
+ "offset" => 10000,
155
+ "limit" => -1,
156
+ },
157
+ },
158
+ },
159
+ },
160
+ :attributes => {
161
+ :expected => {
162
+ "count" => 2,
163
+ "records" => [
164
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
165
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
166
+ ],
167
+ },
168
+ :source => {
169
+ "count" => 2,
170
+ "records" => [
171
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
172
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
173
+ ],
174
+ },
175
+ :mapping => {
176
+ "output" => "search_result",
177
+ "elements" => {
178
+ "records" => {
179
+ "attributes" => ["_key", "chapter", "section", "subsection", "paragraph"],
180
+ "limit" => -1,
181
+ },
182
+ },
183
+ },
184
+ },
185
+ :attributes_with_sort_attributes => {
186
+ :expected => {
187
+ "count" => 2,
188
+ "records" => [
189
+ create_record(1, 1.1, 1.2),
190
+ create_record(2, 2.1, 2.2),
191
+ ],
192
+ },
193
+ :source => {
194
+ "count" => 2,
195
+ "records" => [
196
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
197
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
198
+ ],
199
+ },
200
+ :mapping => {
201
+ "output" => "search_result",
202
+ "elements" => {
203
+ "records" => {
204
+ "attributes" => ["_key", "chapter", "section"],
205
+ "limit" => -1,
206
+ },
207
+ },
208
+ },
209
+ },
210
+ :format_simple => {
211
+ :expected => {
212
+ "count" => 2,
213
+ "records" => [
214
+ create_record(1, 1.1, 1.2),
215
+ create_record(2, 2.1, 2.2),
216
+ ],
217
+ },
218
+ :source => {
219
+ "count" => 2,
220
+ "records" => [
221
+ create_record(1, 1.1, 1.2),
222
+ create_record(2, 2.1, 2.2),
223
+ ],
224
+ },
225
+ :mapping => {
226
+ "output" => "search_result",
227
+ "elements" => {
228
+ "records" => {
229
+ "format" => "simple",
230
+ "attributes" => ["_key", "chapter", "section"],
231
+ "limit" => -1,
232
+ },
233
+ },
234
+ },
235
+ },
236
+ :format_complex => {
237
+ :expected => {
238
+ "count" => 2,
239
+ "records" => [
240
+ { "_key" => 1, "chapter" => 1.1, "section" => 1.2 },
241
+ { "_key" => 2, "chapter" => 2.1, "section" => 2.2 },
242
+ ],
243
+ },
244
+ :source => {
245
+ "count" => 2,
246
+ "records" => [
247
+ create_record(1, 1.1, 1.2),
248
+ create_record(2, 2.1, 2.2),
249
+ ],
250
+ },
251
+ :mapping => {
252
+ "output" => "search_result",
253
+ "elements" => {
254
+ "records" => {
255
+ "format" => "complex",
256
+ "attributes" => ["_key", "chapter", "section"],
257
+ "limit" => -1,
258
+ },
259
+ },
260
+ },
261
+ },
262
+ :count_with_records => {
263
+ :expected => {
264
+ "count" => 2,
265
+ "records" => [
266
+ [],
267
+ [],
268
+ ],
269
+ },
270
+ :source => {
271
+ "count" => 5,
272
+ "records" => [
273
+ [],
274
+ [],
275
+ ],
276
+ },
277
+ :mapping => {
278
+ "output" => "search_result",
279
+ "elements" => {
280
+ "count" => {
281
+ "target" => "records",
282
+ },
283
+ "records" => {
284
+ "format" => "simple",
285
+ "attributes" => [],
286
+ "limit" => -1,
287
+ },
288
+ },
289
+ },
290
+ },
291
+ :count_only => {
292
+ :expected => {
293
+ "count" => 2,
294
+ },
295
+ :source => {
296
+ "count" => 5,
297
+ "records" => [
298
+ [],
299
+ [],
300
+ ],
301
+ },
302
+ :mapping => {
303
+ "output" => "search_result",
304
+ "elements" => {
305
+ "count" => {
306
+ "target" => "records",
307
+ },
308
+ "records" => {
309
+ "format" => "simple",
310
+ "attributes" => [],
311
+ "limit" => -1,
312
+ "no_output" => true,
313
+ },
314
+ },
315
+ },
316
+ },
317
+ )
318
+ def test_gather(data)
319
+ request = {
320
+ "task" => {
321
+ "values" => {},
322
+ "step" => {
323
+ "body" => nil,
324
+ "outputs" => nil,
325
+ },
326
+ },
327
+ "id" => nil,
328
+ "value" => data[:source],
329
+ "name" => data[:mapping],
330
+ "descendants" => nil,
331
+ }
332
+ output_name = data[:mapping]
333
+ output_name = output_name["output"] if output_name.is_a?(Hash)
334
+ assert_equal({ output_name => data[:expected] },
335
+ gather(request))
336
+ end
337
+ end
338
+
339
+ class ReduceTest < self
340
+ def test_sum
341
+ input_name = "input_#{Time.now.to_i}"
342
+ output_name = "output_#{Time.now.to_i}"
343
+ request = {
344
+ "task" => {
345
+ "values" => {
346
+ output_name => {
347
+ "numeric_value" => 1,
348
+ "numeric_key_records" => [
349
+ create_record(1),
350
+ create_record(2),
351
+ create_record(3),
352
+ ],
353
+ "string_key_records" => [
354
+ create_record("a"),
355
+ create_record("b"),
356
+ create_record("c"),
357
+ ],
358
+ },
359
+ },
360
+ "step" => {
361
+ "body" => {
362
+ input_name => {
363
+ output_name => {
364
+ "numeric_value" => {
365
+ "type" => "sum",
366
+ "limit" => -1,
367
+ },
368
+ "numeric_key_records" => {
369
+ "type" => "sum",
370
+ "limit" => -1,
371
+ },
372
+ "string_key_records" => {
373
+ "type" => "sum",
374
+ "limit" => -1,
375
+ },
376
+ },
377
+ },
378
+ },
379
+ "outputs" => nil,
380
+ },
381
+ },
382
+ "id" => nil,
383
+ "value" => {
384
+ "numeric_value" => 2,
385
+ "numeric_key_records" => [
386
+ create_record(4),
387
+ create_record(5),
388
+ create_record(6),
389
+ ],
390
+ "string_key_records" => [
391
+ create_record("d"),
392
+ create_record("e"),
393
+ create_record("f"),
394
+ ],
395
+ },
396
+ "name" => input_name,
397
+ "descendants" => nil,
398
+ }
399
+ assert_equal({
400
+ output_name => {
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
+ reduce(request))
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
+ "step" => {
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
+ assert_equal({
483
+ output_name => {
484
+ "numeric_value" => 3,
485
+ "numeric_key_records" => [
486
+ create_record(1),
487
+ create_record(2),
488
+ ],
489
+ "string_key_records" => [
490
+ create_record("a"),
491
+ create_record("b"),
492
+ create_record("c"),
493
+ create_record("d"),
494
+ create_record("e"),
495
+ create_record("f"),
496
+ ],
497
+ },
498
+ },
499
+ reduce(request))
500
+ end
501
+
502
+ def test_sort
503
+ input_name = "input_#{Time.now.to_i}"
504
+ output_name = "output_#{Time.now.to_i}"
505
+ request = {
506
+ "task" => {
507
+ "values" => {
508
+ output_name => {
509
+ "numeric_key_records" => [
510
+ create_record(1),
511
+ create_record(3),
512
+ create_record(5),
513
+ ],
514
+ "string_key_records" => [
515
+ create_record("a"),
516
+ create_record("c"),
517
+ create_record("e"),
518
+ ],
519
+ },
520
+ },
521
+ "step" => {
522
+ "body" => {
523
+ input_name => {
524
+ output_name => {
525
+ "numeric_key_records" => {
526
+ "type" => "sort",
527
+ "operators" => [
528
+ { "column" => 0, "operator" => "<" },
529
+ ],
530
+ "limit" => -1,
531
+ },
532
+ "string_key_records" => {
533
+ "type" => "sort",
534
+ "operators" => [
535
+ { "column" => 0, "operator" => "<" },
536
+ ],
537
+ "limit" => -1,
538
+ },
539
+ },
540
+ },
541
+ },
542
+ "outputs" => nil,
543
+ },
544
+ },
545
+ "id" => nil,
546
+ "value" => {
547
+ "numeric_key_records" => [
548
+ create_record(2),
549
+ create_record(4),
550
+ create_record(6),
551
+ ],
552
+ "string_key_records" => [
553
+ create_record("b"),
554
+ create_record("d"),
555
+ create_record("f"),
556
+ ],
557
+ },
558
+ "name" => input_name,
559
+ "descendants" => nil,
560
+ }
561
+ assert_equal({
562
+ output_name => {
563
+ "numeric_key_records" => [
564
+ create_record(1),
565
+ create_record(2),
566
+ create_record(3),
567
+ create_record(4),
568
+ create_record(5),
569
+ create_record(6),
570
+ ],
571
+ "string_key_records" => [
572
+ create_record("a"),
573
+ create_record("b"),
574
+ create_record("c"),
575
+ create_record("d"),
576
+ create_record("e"),
577
+ create_record("f"),
578
+ ],
579
+ },
580
+ },
581
+ reduce(request))
582
+ end
583
+
584
+ def test_sort_with_limit
585
+ input_name = "input_#{Time.now.to_i}"
586
+ output_name = "output_#{Time.now.to_i}"
587
+ request = {
588
+ "task" => {
589
+ "values" => {
590
+ output_name => {
591
+ "numeric_key_records" => [
592
+ create_record(1),
593
+ create_record(3),
594
+ create_record(5),
595
+ ],
596
+ "string_key_records" => [
597
+ create_record("a"),
598
+ create_record("c"),
599
+ create_record("e"),
600
+ ],
601
+ },
602
+ },
603
+ "step" => {
604
+ "body" => {
605
+ input_name => {
606
+ output_name => {
607
+ "numeric_key_records" => {
608
+ "type" => "sort",
609
+ "operators" => [
610
+ { "column" => 0, "operator" => "<" },
611
+ ],
612
+ "limit" => 2,
613
+ },
614
+ "string_key_records" => {
615
+ "type" => "sort",
616
+ "operators" => [
617
+ { "column" => 0, "operator" => "<" },
618
+ ],
619
+ "limit" => -1,
620
+ },
621
+ },
622
+ },
623
+ },
624
+ "outputs" => nil,
625
+ },
626
+ },
627
+ "id" => nil,
628
+ "value" => {
629
+ "numeric_key_records" => [
630
+ create_record(2),
631
+ create_record(4),
632
+ create_record(6),
633
+ ],
634
+ "string_key_records" => [
635
+ create_record("b"),
636
+ create_record("d"),
637
+ create_record("f"),
638
+ ],
639
+ },
640
+ "name" => input_name,
641
+ "descendants" => nil,
642
+ }
643
+ assert_equal({
644
+ output_name => {
645
+ "numeric_key_records" => [
646
+ create_record(1),
647
+ create_record(2),
648
+ ],
649
+ "string_key_records" => [
650
+ create_record("a"),
651
+ create_record("b"),
652
+ create_record("c"),
653
+ create_record("d"),
654
+ create_record("e"),
655
+ create_record("f"),
656
+ ],
657
+ },
658
+ },
659
+ reduce(request))
660
+ end
661
+ end
662
+
663
+ class MergeTest < self
664
+ def test_grouped
665
+ input_name = "input_#{Time.now.to_i}"
666
+ output_name = "output_#{Time.now.to_i}"
667
+ request = {
668
+ "task" => {
669
+ "values" => {
670
+ output_name => {
671
+ "records" => [
672
+ [
673
+ "group1",
674
+ 10,
675
+ [
676
+ create_record(1),
677
+ create_record(3),
678
+ create_record(5),
679
+ ],
680
+ ],
681
+ [
682
+ "group2",
683
+ 20,
684
+ [
685
+ create_record("a"),
686
+ create_record("c"),
687
+ create_record("e"),
688
+ ],
689
+ ],
690
+ [
691
+ "group3",
692
+ 30,
693
+ [
694
+ create_record("A"),
695
+ create_record("B"),
696
+ create_record("C"),
697
+ ],
698
+ ],
699
+ ],
700
+ },
701
+ },
702
+ "step" => {
703
+ "body" => {
704
+ input_name => {
705
+ output_name => {
706
+ "records" => {
707
+ "type" => "sort",
708
+ "operators" => [
709
+ { "column" => 1, "operator" => "<" },
710
+ ],
711
+ "key_column" => 0,
712
+ "limit" => -1,
713
+ },
714
+ },
715
+ },
716
+ },
717
+ "outputs" => nil,
718
+ },
719
+ },
720
+ "id" => nil,
721
+ "value" => {
722
+ "records" => [
723
+ [
724
+ "group1",
725
+ 30,
726
+ [
727
+ create_record(2),
728
+ create_record(4),
729
+ create_record(6),
730
+ ],
731
+ ],
732
+ [
733
+ "group2",
734
+ 40,
735
+ [
736
+ create_record("b"),
737
+ create_record("d"),
738
+ create_record("f"),
739
+ ],
740
+ ],
741
+ [
742
+ "group4",
743
+ 50,
744
+ [
745
+ create_record("D"),
746
+ create_record("E"),
747
+ create_record("F"),
748
+ ],
749
+ ],
750
+ ],
751
+ },
752
+ "name" => input_name,
753
+ "descendants" => nil,
754
+ }
755
+ assert_equal({
756
+ output_name => {
757
+ "records" => [
758
+ [
759
+ "group3",
760
+ 30,
761
+ [
762
+ create_record("A"),
763
+ create_record("B"),
764
+ create_record("C"),
765
+ ],
766
+ ],
767
+ [
768
+ "group1",
769
+ 40,
770
+ [
771
+ create_record(2),
772
+ create_record(4),
773
+ create_record(6),
774
+ create_record(1),
775
+ create_record(3),
776
+ create_record(5),
777
+ ],
778
+ ],
779
+ [
780
+ "group4",
781
+ 50,
782
+ [
783
+ create_record("D"),
784
+ create_record("E"),
785
+ create_record("F"),
786
+ ],
787
+ ],
788
+ [
789
+ "group2",
790
+ 60,
791
+ [
792
+ create_record("b"),
793
+ create_record("d"),
794
+ create_record("f"),
795
+ create_record("a"),
796
+ create_record("c"),
797
+ create_record("e"),
798
+ ],
799
+ ],
800
+ ],
801
+ },
802
+ },
803
+ reduce(request))
804
+ end
805
+ end
806
+ end