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,174 @@
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 SearchPlannerTest < Test::Unit::TestCase
19
+ def setup
20
+ setup_database
21
+ @planner = Droonga::Test::StubPlanner.new
22
+ @plugin = Droonga::Plugins::Search::Planner.new
23
+ end
24
+
25
+ def teardown
26
+ teardown_database
27
+ end
28
+
29
+ def test_distribute
30
+ envelope = {
31
+ "type" => "search",
32
+ "dataset" => "Droonga",
33
+ "body" => {
34
+ "queries" => {
35
+ "query1" => {
36
+ "source" => "User",
37
+ "output" => {
38
+ "format" => "complex",
39
+ "elements" => ["count", "records"],
40
+ "attributes" => [],
41
+ "offset" => 0,
42
+ "limit" => 10,
43
+ },
44
+ },
45
+ "query2" => {
46
+ "source" => "User",
47
+ "output" => {
48
+ "format" => "complex",
49
+ "elements" => ["count", "records"],
50
+ "attributes" => [],
51
+ "offset" => 0,
52
+ "limit" => 20,
53
+ },
54
+ },
55
+ },
56
+ },
57
+ }
58
+
59
+ @planner.distribute(@plugin.plan(envelope))
60
+
61
+ message = []
62
+
63
+ message << {
64
+ "type" => "search_reduce",
65
+ "body" => {
66
+ "errors" => {
67
+ "errors_reduced" => {
68
+ "limit" => -1,
69
+ "type" => "sum",
70
+ },
71
+ },
72
+ "query1" => {
73
+ "query1_reduced" => {
74
+ "count" => {
75
+ "type" => "sum",
76
+ },
77
+ "records" => {
78
+ "type" => "sort",
79
+ "operators" => [],
80
+ "limit" => 10,
81
+ },
82
+ },
83
+ },
84
+ "query2" => {
85
+ "query2_reduced" => {
86
+ "count" => {
87
+ "type" => "sum",
88
+ },
89
+ "records" => {
90
+ "type" => "sort",
91
+ "operators" => [],
92
+ "limit" => 20,
93
+ },
94
+ },
95
+ },
96
+ },
97
+ "inputs" => ["errors", "query1", "query2"],
98
+ "outputs" => ["errors_reduced", "query1_reduced", "query2_reduced"],
99
+ }
100
+
101
+ gatherer = {
102
+ "type" => "search_gather",
103
+ "body" => {
104
+ "errors_reduced" => {
105
+ "output" => "errors",
106
+ },
107
+ "query1_reduced" => {
108
+ "output" => "query1",
109
+ "elements" => {
110
+ "records" => {
111
+ "limit" => 10,
112
+ "format" => "complex",
113
+ },
114
+ },
115
+ },
116
+ "query2_reduced" => {
117
+ "output" => "query2",
118
+ "elements" => {
119
+ "records" => {
120
+ "limit" => 20,
121
+ "format" => "complex",
122
+ },
123
+ },
124
+ },
125
+ },
126
+ "inputs" => [
127
+ "errors_reduced",
128
+ "query1_reduced",
129
+ "query2_reduced",
130
+ ],
131
+ "post" => true,
132
+ }
133
+ message << gatherer
134
+
135
+ searcher = {
136
+ "type" => "broadcast",
137
+ "command" => "search",
138
+ "dataset" => "Droonga",
139
+ "body" => {
140
+ "queries" => {
141
+ "query1" => {
142
+ "source" => "User",
143
+ "output" => {
144
+ "format" => "simple",
145
+ "elements" => ["count", "records"],
146
+ "attributes" => [],
147
+ "offset" => 0,
148
+ "limit" => 10,
149
+ },
150
+ },
151
+ "query2" => {
152
+ "source" => "User",
153
+ "output" => {
154
+ "format" => "simple",
155
+ "elements" => ["count", "records"],
156
+ "attributes" => [],
157
+ "offset" => 0,
158
+ "limit" => 20,
159
+ },
160
+ },
161
+ },
162
+ },
163
+ "outputs" => [
164
+ "errors",
165
+ "query1",
166
+ "query2",
167
+ ],
168
+ "replica" => "random",
169
+ }
170
+ message << searcher
171
+
172
+ assert_equal([message], @planner.messages)
173
+ end
174
+ end
@@ -0,0 +1,510 @@
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/basic"
17
+
18
+ class BasicCollectorTest < 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::Basic::GatherCollector.new
40
+ run_collector(collector, message)
41
+ end
42
+
43
+ def reduce(message)
44
+ collector = Droonga::Plugins::Basic::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 IOTest < self
55
+ data(
56
+ :simple_mapping => {
57
+ :expected => { "output_name" => "result" },
58
+ :source => "result",
59
+ :mapping => "output_name",
60
+ },
61
+ :complex_mapping => {
62
+ :expected => { "output_name" => "result" },
63
+ :source => "result",
64
+ :mapping => {
65
+ "output" => "output_name",
66
+ },
67
+ },
68
+ )
69
+ def test_gather(data)
70
+ request = {
71
+ "task" => {
72
+ "values" => {},
73
+ "step" => {
74
+ "body" => nil,
75
+ "outputs" => nil,
76
+ },
77
+ },
78
+ "id" => nil,
79
+ "value" => data[:source],
80
+ "name" => data[:mapping],
81
+ "descendants" => nil,
82
+ }
83
+ assert_equal(data[:expected], gather(request))
84
+ end
85
+
86
+ def test_reduce
87
+ input_name = "input_#{Time.now.to_i}"
88
+ output_name = "output_#{Time.now.to_i}"
89
+ request = {
90
+ "task" => {
91
+ "values" => {
92
+ output_name => [0, 1, 2],
93
+ },
94
+ "step" => {
95
+ "body" => {
96
+ input_name => {
97
+ output_name => {
98
+ "type" => "sum",
99
+ "limit" => -1,
100
+ },
101
+ },
102
+ },
103
+ "outputs" => nil,
104
+ },
105
+ },
106
+ "id" => nil,
107
+ "value" => [3, 4, 5],
108
+ "name" => input_name,
109
+ "descendants" => nil,
110
+ }
111
+ assert_equal({ output_name => [0, 1, 2, 3, 4, 5] },
112
+ reduce(request))
113
+ end
114
+ end
115
+
116
+ # TODO: Split file
117
+ class ReducerTest < self
118
+ def reduce_value(deal, left_value, right_value)
119
+ reducer = Droonga::Reducer.new(deal)
120
+ reducer.reduce(left_value, right_value)
121
+ end
122
+
123
+ data(
124
+ :int => {
125
+ :expected => 1.5,
126
+ :left => 1,
127
+ :right => 2,
128
+ },
129
+ :float => {
130
+ :expected => 1.5,
131
+ :left => 1.0,
132
+ :right => 2.0,
133
+ },
134
+ )
135
+ def test_average(data)
136
+ reduced = reduce_value({ "type" => "average" },
137
+ data[:left],
138
+ data[:right])
139
+ assert_equal(data[:expected], reduced)
140
+ end
141
+
142
+ data(
143
+ :true_and_false => {
144
+ :expected => false,
145
+ :left => true,
146
+ :right => false,
147
+ },
148
+ :false_and_true => {
149
+ :expected => false,
150
+ :left => false,
151
+ :right => true,
152
+ },
153
+ :both_true => {
154
+ :expected => true,
155
+ :left => true,
156
+ :right => true,
157
+ },
158
+ :both_false => {
159
+ :expected => false,
160
+ :left => false,
161
+ :right => false,
162
+ },
163
+ )
164
+ def test_and(data)
165
+ reduced = reduce_value({ "type" => "and" },
166
+ data[:left],
167
+ data[:right])
168
+ assert_equal(data[:expected], reduced)
169
+ end
170
+
171
+ data(
172
+ :true_and_false => {
173
+ :expected => true,
174
+ :left => true,
175
+ :right => false,
176
+ },
177
+ :false_and_true => {
178
+ :expected => true,
179
+ :left => false,
180
+ :right => true,
181
+ },
182
+ :both_true => {
183
+ :expected => true,
184
+ :left => true,
185
+ :right => true,
186
+ },
187
+ :both_false => {
188
+ :expected => false,
189
+ :left => false,
190
+ :right => false,
191
+ },
192
+ )
193
+ def test_or(data)
194
+ reduced = reduce_value({ "type" => "or" },
195
+ data[:left],
196
+ data[:right])
197
+ assert_equal(data[:expected], reduced)
198
+ end
199
+
200
+ data(
201
+ :numeric_values => {
202
+ :expected => 3,
203
+ :left => 1,
204
+ :right => 2,
205
+ },
206
+ :numeric_key_records => {
207
+ :expected => [
208
+ create_record(1),
209
+ create_record(2),
210
+ create_record(3),
211
+ create_record(4),
212
+ create_record(5),
213
+ create_record(6),
214
+ ],
215
+ :left => [
216
+ create_record(1),
217
+ create_record(2),
218
+ create_record(3),
219
+ ],
220
+ :right => [
221
+ create_record(4),
222
+ create_record(5),
223
+ create_record(6),
224
+ ],
225
+ },
226
+ :string_key_records => {
227
+ :expected => [
228
+ create_record("a"),
229
+ create_record("b"),
230
+ create_record("c"),
231
+ create_record("d"),
232
+ create_record("e"),
233
+ create_record("f"),
234
+ ],
235
+ :left => [
236
+ create_record("a"),
237
+ create_record("b"),
238
+ create_record("c"),
239
+ ],
240
+ :right => [
241
+ create_record("d"),
242
+ create_record("e"),
243
+ create_record("f"),
244
+ ],
245
+ },
246
+ :numeric_values_with_limit => {
247
+ :expected => 3,
248
+ :left => 1,
249
+ :right => 2,
250
+ :limit => 2,
251
+ },
252
+ :numeric_key_records_with_limit => {
253
+ :expected => [
254
+ create_record(1),
255
+ create_record(2),
256
+ ],
257
+ :left => [
258
+ create_record(1),
259
+ create_record(2),
260
+ create_record(3),
261
+ ],
262
+ :right => [
263
+ create_record(4),
264
+ create_record(5),
265
+ create_record(6),
266
+ ],
267
+ :limit => 2,
268
+ },
269
+ :string_key_records_with_limit => {
270
+ :expected => [
271
+ create_record("a"),
272
+ create_record("b"),
273
+ ],
274
+ :left => [
275
+ create_record("a"),
276
+ create_record("b"),
277
+ create_record("c"),
278
+ ],
279
+ :right => [
280
+ create_record("d"),
281
+ create_record("e"),
282
+ create_record("f"),
283
+ ],
284
+ :limit => 2,
285
+ },
286
+ )
287
+ def test_sum(data)
288
+ reduced = reduce_value({ "type" => "sum",
289
+ "limit" => data[:limit] || -1 },
290
+ data[:left],
291
+ data[:right])
292
+ assert_equal(data[:expected], reduced)
293
+ end
294
+
295
+ data(
296
+ :numeric_key_records => {
297
+ :expected => [
298
+ create_record(1),
299
+ create_record(2),
300
+ create_record(3),
301
+ create_record(4),
302
+ create_record(5),
303
+ create_record(6),
304
+ ],
305
+ :left => [
306
+ create_record(1),
307
+ create_record(3),
308
+ create_record(5),
309
+ ],
310
+ :right => [
311
+ create_record(2),
312
+ create_record(4),
313
+ create_record(6),
314
+ ],
315
+ },
316
+ :string_key_records => {
317
+ :expected => [
318
+ create_record("a"),
319
+ create_record("b"),
320
+ create_record("c"),
321
+ create_record("d"),
322
+ create_record("e"),
323
+ create_record("f"),
324
+ ],
325
+ :left => [
326
+ create_record("a"),
327
+ create_record("c"),
328
+ create_record("e"),
329
+ ],
330
+ :right => [
331
+ create_record("b"),
332
+ create_record("d"),
333
+ create_record("f"),
334
+ ],
335
+ },
336
+ :numeric_key_records_with_limit => {
337
+ :expected => [
338
+ create_record(1),
339
+ create_record(2),
340
+ ],
341
+ :left => [
342
+ create_record(1),
343
+ create_record(3),
344
+ create_record(5),
345
+ ],
346
+ :right => [
347
+ create_record(2),
348
+ create_record(4),
349
+ create_record(6),
350
+ ],
351
+ :limit => 2,
352
+ },
353
+ :string_key_records_with_limit => {
354
+ :expected => [
355
+ create_record("a"),
356
+ create_record("b"),
357
+ ],
358
+ :left => [
359
+ create_record("a"),
360
+ create_record("c"),
361
+ create_record("e"),
362
+ ],
363
+ :right => [
364
+ create_record("b"),
365
+ create_record("d"),
366
+ create_record("f"),
367
+ ],
368
+ :limit => 2,
369
+ },
370
+ )
371
+ def test_sort(data)
372
+ reduced = reduce_value({
373
+ "type" => "sort",
374
+ "operators" => [
375
+ { "column" => 0, "operator" => "<" },
376
+ ],
377
+ "limit" => data[:limit] || -1,
378
+ },
379
+ data[:left],
380
+ data[:right])
381
+ assert_equal(data[:expected], reduced)
382
+ end
383
+ end
384
+
385
+ # TODO: Split file
386
+ class MergeTest < self
387
+ def reduce_value(deal, left_value, right_value)
388
+ reducer = Droonga::Reducer.new(deal)
389
+ reducer.reduce(left_value, right_value)
390
+ end
391
+
392
+ def test_grouped
393
+ expected = [
394
+ [
395
+ "group3",
396
+ 30,
397
+ [
398
+ create_record("A"),
399
+ create_record("B"),
400
+ create_record("C"),
401
+ ],
402
+ ],
403
+ [
404
+ "group1",
405
+ 40,
406
+ [
407
+ create_record(2),
408
+ create_record(4),
409
+ create_record(6),
410
+ create_record(1),
411
+ create_record(3),
412
+ create_record(5),
413
+ ],
414
+ ],
415
+ [
416
+ "group4",
417
+ 50,
418
+ [
419
+ create_record("D"),
420
+ create_record("E"),
421
+ create_record("F"),
422
+ ],
423
+ ],
424
+ [
425
+ "group2",
426
+ 60,
427
+ [
428
+ create_record("b"),
429
+ create_record("d"),
430
+ create_record("f"),
431
+ create_record("a"),
432
+ create_record("c"),
433
+ create_record("e"),
434
+ ],
435
+ ],
436
+ ]
437
+
438
+ left = [
439
+ [
440
+ "group1",
441
+ 10,
442
+ [
443
+ create_record(1),
444
+ create_record(3),
445
+ create_record(5),
446
+ ],
447
+ ],
448
+ [
449
+ "group2",
450
+ 20,
451
+ [
452
+ create_record("a"),
453
+ create_record("c"),
454
+ create_record("e"),
455
+ ],
456
+ ],
457
+ [
458
+ "group3",
459
+ 30,
460
+ [
461
+ create_record("A"),
462
+ create_record("B"),
463
+ create_record("C"),
464
+ ],
465
+ ],
466
+ ]
467
+ right = [
468
+ [
469
+ "group1",
470
+ 30,
471
+ [
472
+ create_record(2),
473
+ create_record(4),
474
+ create_record(6),
475
+ ],
476
+ ],
477
+ [
478
+ "group2",
479
+ 40,
480
+ [
481
+ create_record("b"),
482
+ create_record("d"),
483
+ create_record("f"),
484
+ ],
485
+ ],
486
+ [
487
+ "group4",
488
+ 50,
489
+ [
490
+ create_record("D"),
491
+ create_record("E"),
492
+ create_record("F"),
493
+ ],
494
+ ],
495
+ ]
496
+
497
+ reduced = reduce_value({
498
+ "type" => "sort",
499
+ "operators" => [
500
+ { "column" => 1, "operator" => "<" },
501
+ ],
502
+ "key_column" => 0,
503
+ "limit" => -1,
504
+ },
505
+ left,
506
+ right)
507
+ assert_equal(expected, reduced)
508
+ end
509
+ end
510
+ end