droonga-engine 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.dir-locals.el +3 -0
- data/.gitignore +6 -0
- data/.travis.yml +15 -0
- data/.yardopts +7 -0
- data/Gemfile +66 -0
- data/LICENSE.txt +14 -0
- data/README.md +17 -0
- data/Rakefile +64 -0
- data/benchmark/benchmark.rb +123 -0
- data/benchmark/utils.rb +246 -0
- data/benchmark/watch/benchmark-notify.rb +143 -0
- data/benchmark/watch/benchmark-notify.sh +20 -0
- data/benchmark/watch/benchmark-publish.rb +120 -0
- data/benchmark/watch/benchmark-scan.rb +213 -0
- data/bin/droonga-catalog-generate +103 -0
- data/bin/droonga-engine +20 -0
- data/bin/droonga-engine-service +20 -0
- data/doc/text/news.md +106 -0
- data/droonga-engine.gemspec +52 -0
- data/lib/droonga/adapter.rb +48 -0
- data/lib/droonga/adapter_runner.rb +104 -0
- data/lib/droonga/catalog/base.rb +41 -0
- data/lib/droonga/catalog/collection_volume.rb +106 -0
- data/lib/droonga/catalog/dataset.rb +69 -0
- data/lib/droonga/catalog/errors.rb +113 -0
- data/lib/droonga/catalog/schema.rb +186 -0
- data/lib/droonga/catalog/single_volume.rb +28 -0
- data/lib/droonga/catalog/slice.rb +41 -0
- data/lib/droonga/catalog/version1.rb +427 -0
- data/lib/droonga/catalog/version2.rb +96 -0
- data/lib/droonga/catalog/version2_validator.rb +63 -0
- data/lib/droonga/catalog/volume.rb +33 -0
- data/lib/droonga/catalog/volume_collection.rb +56 -0
- data/lib/droonga/catalog_generator.rb +156 -0
- data/lib/droonga/catalog_loader.rb +56 -0
- data/lib/droonga/catalog_observer.rb +83 -0
- data/lib/droonga/collector.rb +38 -0
- data/lib/droonga/collector_message.rb +71 -0
- data/lib/droonga/collector_runner.rb +64 -0
- data/lib/droonga/collectors/and.rb +26 -0
- data/lib/droonga/collectors/or.rb +26 -0
- data/lib/droonga/collectors/sum.rb +26 -0
- data/lib/droonga/collectors.rb +18 -0
- data/lib/droonga/dispatcher.rb +326 -0
- data/lib/droonga/distributed_command_planner.rb +179 -0
- data/lib/droonga/distributor.rb +87 -0
- data/lib/droonga/engine/command/droonga_engine.rb +441 -0
- data/lib/droonga/engine/version.rb +20 -0
- data/lib/droonga/engine.rb +80 -0
- data/lib/droonga/engine_state.rb +79 -0
- data/lib/droonga/error.rb +73 -0
- data/lib/droonga/error_messages.rb +33 -0
- data/lib/droonga/event_loop.rb +46 -0
- data/lib/droonga/farm.rb +58 -0
- data/lib/droonga/fluent_message_receiver.rb +191 -0
- data/lib/droonga/fluent_message_sender.rb +140 -0
- data/lib/droonga/forwarder.rb +119 -0
- data/lib/droonga/handler.rb +49 -0
- data/lib/droonga/handler_message.rb +61 -0
- data/lib/droonga/handler_messenger.rb +119 -0
- data/lib/droonga/handler_runner.rb +125 -0
- data/lib/droonga/input_message.rb +51 -0
- data/lib/droonga/job_protocol.rb +20 -0
- data/lib/droonga/job_pusher.rb +179 -0
- data/lib/droonga/job_receiver.rb +70 -0
- data/lib/droonga/loggable.rb +29 -0
- data/lib/droonga/logger.rb +142 -0
- data/lib/droonga/message_matcher.rb +109 -0
- data/lib/droonga/output_message.rb +55 -0
- data/lib/droonga/planner.rb +47 -0
- data/lib/droonga/pluggable.rb +31 -0
- data/lib/droonga/plugin/metadata/adapter_input_message.rb +39 -0
- data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
- data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
- data/lib/droonga/plugin/metadata/handler_action.rb +39 -0
- data/lib/droonga/plugin/metadata/input_message.rb +54 -0
- data/lib/droonga/plugin.rb +43 -0
- data/lib/droonga/plugin_loader.rb +63 -0
- data/lib/droonga/plugin_registry.rb +66 -0
- data/lib/droonga/plugins/basic.rb +54 -0
- data/lib/droonga/plugins/crud.rb +145 -0
- data/lib/droonga/plugins/dump.rb +97 -0
- data/lib/droonga/plugins/error.rb +51 -0
- data/lib/droonga/plugins/groonga/column_create.rb +123 -0
- data/lib/droonga/plugins/groonga/column_list.rb +124 -0
- data/lib/droonga/plugins/groonga/column_remove.rb +65 -0
- data/lib/droonga/plugins/groonga/column_rename.rb +67 -0
- data/lib/droonga/plugins/groonga/delete.rb +117 -0
- data/lib/droonga/plugins/groonga/generic_command.rb +105 -0
- data/lib/droonga/plugins/groonga/generic_response.rb +43 -0
- data/lib/droonga/plugins/groonga/select.rb +236 -0
- data/lib/droonga/plugins/groonga/table_create.rb +111 -0
- data/lib/droonga/plugins/groonga/table_list.rb +120 -0
- data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
- data/lib/droonga/plugins/groonga.rb +37 -0
- data/lib/droonga/plugins/search/distributed_search_planner.rb +407 -0
- data/lib/droonga/plugins/search.rb +146 -0
- data/lib/droonga/plugins/watch.rb +178 -0
- data/lib/droonga/processor.rb +63 -0
- data/lib/droonga/reducer.rb +169 -0
- data/lib/droonga/replier.rb +49 -0
- data/lib/droonga/schema_applier.rb +167 -0
- data/lib/droonga/searcher/mecab_filter.rb +67 -0
- data/lib/droonga/searcher.rb +733 -0
- data/lib/droonga/server.rb +45 -0
- data/lib/droonga/session.rb +99 -0
- data/lib/droonga/single_step.rb +68 -0
- data/lib/droonga/single_step_definition.rb +54 -0
- data/lib/droonga/slice.rb +122 -0
- data/lib/droonga/status_code.rb +25 -0
- data/lib/droonga/step_runner.rb +64 -0
- data/lib/droonga/sweeper.rb +42 -0
- data/lib/droonga/test/stub_handler.rb +37 -0
- data/lib/droonga/test/stub_handler_message.rb +35 -0
- data/lib/droonga/test/stub_handler_messenger.rb +34 -0
- data/lib/droonga/test/stub_planner.rb +31 -0
- data/lib/droonga/test.rb +21 -0
- data/lib/droonga/watch_schema.rb +92 -0
- data/lib/droonga/watcher.rb +257 -0
- data/lib/droonga/worker.rb +61 -0
- data/sample/cluster/catalog.json +42 -0
- data/sample/mecab_filter/data.grn +7 -0
- data/sample/mecab_filter/ddl.grn +7 -0
- data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
- data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
- data/test/command/config/default/catalog.json +85 -0
- data/test/command/config/default/fluentd.conf +11 -0
- data/test/command/config/version1/catalog.json +68 -0
- data/test/command/config/version1/fluentd.conf +11 -0
- data/test/command/fixture/documents.jsons +208 -0
- data/test/command/fixture/event.jsons +41 -0
- data/test/command/fixture/user-table-array.jsons +38 -0
- data/test/command/fixture/user-table.jsons +47 -0
- data/test/command/run-test.rb +34 -0
- data/test/command/suite/add/dimension/column.catalog.json +28 -0
- data/test/command/suite/add/dimension/column.expected +41 -0
- data/test/command/suite/add/dimension/column.test +51 -0
- data/test/command/suite/add/dimension/integer.catalog.json +19 -0
- data/test/command/suite/add/dimension/integer.expected +41 -0
- data/test/command/suite/add/dimension/integer.test +51 -0
- data/test/command/suite/add/error/invalid-integer.expected +46 -0
- data/test/command/suite/add/error/invalid-integer.test +12 -0
- data/test/command/suite/add/error/invalid-time.expected +46 -0
- data/test/command/suite/add/error/invalid-time.test +12 -0
- data/test/command/suite/add/error/missing-key.expected +25 -0
- data/test/command/suite/add/error/missing-key.test +16 -0
- data/test/command/suite/add/error/missing-table.expected +25 -0
- data/test/command/suite/add/error/missing-table.test +16 -0
- data/test/command/suite/add/error/unknown-column.expected +46 -0
- data/test/command/suite/add/error/unknown-column.test +12 -0
- data/test/command/suite/add/error/unknown-table.expected +25 -0
- data/test/command/suite/add/error/unknown-table.test +17 -0
- data/test/command/suite/add/minimum.expected +6 -0
- data/test/command/suite/add/minimum.test +11 -0
- data/test/command/suite/add/with-values.expected +6 -0
- data/test/command/suite/add/with-values.test +17 -0
- data/test/command/suite/add/without-key.expected +6 -0
- data/test/command/suite/add/without-key.test +16 -0
- data/test/command/suite/groonga/column_create/scalar.expected +26 -0
- data/test/command/suite/groonga/column_create/scalar.test +17 -0
- data/test/command/suite/groonga/column_create/unknown-table.expected +14 -0
- data/test/command/suite/groonga/column_create/unknown-table.test +7 -0
- data/test/command/suite/groonga/column_create/vector.expected +26 -0
- data/test/command/suite/groonga/column_create/vector.test +18 -0
- data/test/command/suite/groonga/column_list/success.expected +86 -0
- data/test/command/suite/groonga/column_list/success.test +24 -0
- data/test/command/suite/groonga/column_list/unknown-table.expected +13 -0
- data/test/command/suite/groonga/column_list/unknown-table.test +7 -0
- data/test/command/suite/groonga/column_remove/success.expected +39 -0
- data/test/command/suite/groonga/column_remove/success.test +25 -0
- data/test/command/suite/groonga/column_remove/unknown-column.expected +27 -0
- data/test/command/suite/groonga/column_remove/unknown-column.test +16 -0
- data/test/command/suite/groonga/column_remove/unknown-table.expected +14 -0
- data/test/command/suite/groonga/column_remove/unknown-table.test +7 -0
- data/test/command/suite/groonga/column_rename/success.expected +39 -0
- data/test/command/suite/groonga/column_rename/success.test +26 -0
- data/test/command/suite/groonga/column_rename/unknown-column.expected +27 -0
- data/test/command/suite/groonga/column_rename/unknown-column.test +16 -0
- data/test/command/suite/groonga/column_rename/unknown-table.expected +14 -0
- data/test/command/suite/groonga/column_rename/unknown-table.test +7 -0
- data/test/command/suite/groonga/delete/duplicated-identifiers.expected +27 -0
- data/test/command/suite/groonga/delete/duplicated-identifiers.test +17 -0
- data/test/command/suite/groonga/delete/filter.expected +19 -0
- data/test/command/suite/groonga/delete/filter.test +19 -0
- data/test/command/suite/groonga/delete/invalid-filter.expected +14 -0
- data/test/command/suite/groonga/delete/invalid-filter.test +9 -0
- data/test/command/suite/groonga/delete/no-identifier.expected +27 -0
- data/test/command/suite/groonga/delete/no-identifier.test +15 -0
- data/test/command/suite/groonga/delete/success.expected +19 -0
- data/test/command/suite/groonga/delete/success.test +19 -0
- data/test/command/suite/groonga/delete/unknown-table.expected +14 -0
- data/test/command/suite/groonga/delete/unknown-table.test +7 -0
- data/test/command/suite/groonga/select/minimum.expected +22 -0
- data/test/command/suite/groonga/select/minimum.test +8 -0
- data/test/command/suite/groonga/table_create/array.expected +14 -0
- data/test/command/suite/groonga/table_create/array.test +8 -0
- data/test/command/suite/groonga/table_create/hash.expected +13 -0
- data/test/command/suite/groonga/table_create/hash.test +8 -0
- data/test/command/suite/groonga/table_list/success.expected +71 -0
- data/test/command/suite/groonga/table_list/success.test +15 -0
- data/test/command/suite/groonga/table_remove/success.expected +13 -0
- data/test/command/suite/groonga/table_remove/success.test +8 -0
- data/test/command/suite/groonga/table_remove/unknown-table.expected +14 -0
- data/test/command/suite/groonga/table_remove/unknown-table.test +7 -0
- data/test/command/suite/message/error/missing-dataset.expected +9 -0
- data/test/command/suite/message/error/missing-dataset.test +5 -0
- data/test/command/suite/message/error/unknown-dataset.expected +9 -0
- data/test/command/suite/message/error/unknown-dataset.test +6 -0
- data/test/command/suite/message/error/unknown-type.expected +9 -0
- data/test/command/suite/message/error/unknown-type.test +6 -0
- data/test/command/suite/search/adjusters/multiple.catalog.json +38 -0
- data/test/command/suite/search/adjusters/multiple.expected +19 -0
- data/test/command/suite/search/adjusters/multiple.test +75 -0
- data/test/command/suite/search/adjusters/one.catalog.json +38 -0
- data/test/command/suite/search/adjusters/one.expected +19 -0
- data/test/command/suite/search/adjusters/one.test +66 -0
- data/test/command/suite/search/attributes/array.expected +21 -0
- data/test/command/suite/search/attributes/array.test +28 -0
- data/test/command/suite/search/attributes/hash.expected +30 -0
- data/test/command/suite/search/attributes/hash.test +36 -0
- data/test/command/suite/search/complex.expected +48 -0
- data/test/command/suite/search/complex.test +23 -0
- data/test/command/suite/search/condition/nested.expected +15 -0
- data/test/command/suite/search/condition/nested.test +27 -0
- data/test/command/suite/search/condition/query/nonexistent_column.catalog.json +37 -0
- data/test/command/suite/search/condition/query/nonexistent_column.expected +48 -0
- data/test/command/suite/search/condition/query/nonexistent_column.test +33 -0
- data/test/command/suite/search/condition/query/syntax_error.catalog.json +36 -0
- data/test/command/suite/search/condition/query/syntax_error.expected +48 -0
- data/test/command/suite/search/condition/query/syntax_error.test +33 -0
- data/test/command/suite/search/condition/query.expected +24 -0
- data/test/command/suite/search/condition/query.test +23 -0
- data/test/command/suite/search/condition/script.expected +24 -0
- data/test/command/suite/search/condition/script.test +26 -0
- data/test/command/suite/search/error/cyclic-source.expected +14 -0
- data/test/command/suite/search/error/cyclic-source.test +12 -0
- data/test/command/suite/search/error/deeply-cyclic-source.expected +17 -0
- data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
- data/test/command/suite/search/error/missing-source-parameter.expected +13 -0
- data/test/command/suite/search/error/missing-source-parameter.test +11 -0
- data/test/command/suite/search/error/no-query.expected +9 -0
- data/test/command/suite/search/error/no-query.test +7 -0
- data/test/command/suite/search/error/unknown-source.expected +52 -0
- data/test/command/suite/search/error/unknown-source.test +12 -0
- data/test/command/suite/search/group/count.expected +10 -0
- data/test/command/suite/search/group/count.test +18 -0
- data/test/command/suite/search/group/limit.expected +15 -0
- data/test/command/suite/search/group/limit.test +20 -0
- data/test/command/suite/search/group/string.expected +32 -0
- data/test/command/suite/search/group/string.test +40 -0
- data/test/command/suite/search/group/subrecord/with-sort.catalog.json +33 -0
- data/test/command/suite/search/group/subrecord/with-sort.expected +30 -0
- data/test/command/suite/search/group/subrecord/with-sort.test +81 -0
- data/test/command/suite/search/multiple/chained.expected +41 -0
- data/test/command/suite/search/multiple/chained.test +39 -0
- data/test/command/suite/search/multiple/parallel.expected +35 -0
- data/test/command/suite/search/multiple/parallel.test +35 -0
- data/test/command/suite/search/output/attributes/invalid.catalog.json +13 -0
- data/test/command/suite/search/output/attributes/invalid.expected +44 -0
- data/test/command/suite/search/output/attributes/invalid.test +28 -0
- data/test/command/suite/search/range/only-output.expected +24 -0
- data/test/command/suite/search/range/only-output.test +23 -0
- data/test/command/suite/search/range/only-sort.expected +24 -0
- data/test/command/suite/search/range/only-sort.test +26 -0
- data/test/command/suite/search/range/sort-and-output.expected +21 -0
- data/test/command/suite/search/range/sort-and-output.test +27 -0
- data/test/command/suite/search/range/too-large-output-offset.expected +12 -0
- data/test/command/suite/search/range/too-large-output-offset.test +23 -0
- data/test/command/suite/search/range/too-large-sort-offset.expected +12 -0
- data/test/command/suite/search/range/too-large-sort-offset.test +26 -0
- data/test/command/suite/search/response/elapsed_time.catalog.json +13 -0
- data/test/command/suite/search/response/elapsed_time.expected +11 -0
- data/test/command/suite/search/response/elapsed_time.test +26 -0
- data/test/command/suite/search/response/records/value/time.expected +20 -0
- data/test/command/suite/search/response/records/value/time.test +22 -0
- data/test/command/suite/search/simple.expected +48 -0
- data/test/command/suite/search/simple.test +22 -0
- data/test/command/suite/search/sort/default-offset-limit.expected +39 -0
- data/test/command/suite/search/sort/default-offset-limit.test +24 -0
- data/test/command/suite/search/sort/invisible-column.expected +24 -0
- data/test/command/suite/search/sort/invisible-column.test +26 -0
- data/test/command/suite/watch/subscribe.expected +6 -0
- data/test/command/suite/watch/subscribe.test +9 -0
- data/test/command/suite/watch/unsubscribe.expected +6 -0
- data/test/command/suite/watch/unsubscribe.test +9 -0
- data/test/performance/run-test.rb +56 -0
- data/test/performance/watch/catalog.json +33 -0
- data/test/performance/watch/feed.json +9 -0
- data/test/performance/watch/fluentd.conf +11 -0
- data/test/performance/watch/subscribe.json +3 -0
- data/test/unit/catalog/test_collection_volume.rb +103 -0
- data/test/unit/catalog/test_dataset.rb +104 -0
- data/test/unit/catalog/test_schema.rb +226 -0
- data/test/unit/catalog/test_single_volume.rb +31 -0
- data/test/unit/catalog/test_slice.rb +92 -0
- data/test/unit/catalog/test_version1.rb +361 -0
- data/test/unit/catalog/test_version2.rb +124 -0
- data/test/unit/catalog/test_version2_validator.rb +66 -0
- data/test/unit/catalog/test_volume_collection.rb +50 -0
- data/test/unit/fixtures/array.grn +18 -0
- data/test/unit/fixtures/catalog/version1.json +40 -0
- data/test/unit/fixtures/catalog/version2.json +62 -0
- data/test/unit/fixtures/document.grn +34 -0
- data/test/unit/fixtures/reference/array.grn +11 -0
- data/test/unit/fixtures/reference/hash.grn +7 -0
- data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
- data/test/unit/helper/fixture.rb +28 -0
- data/test/unit/helper/plugin_helper.rb +38 -0
- data/test/unit/helper/sandbox.rb +86 -0
- data/test/unit/helper/stub_worker.rb +27 -0
- data/test/unit/helper/watch_helper.rb +23 -0
- data/test/unit/helper.rb +28 -0
- data/test/unit/plugins/crud/test_add.rb +190 -0
- data/test/unit/plugins/groonga/select/test_adapter_input.rb +510 -0
- data/test/unit/plugins/groonga/select/test_adapter_output.rb +201 -0
- data/test/unit/plugins/groonga/test_column_create.rb +171 -0
- data/test/unit/plugins/groonga/test_column_list.rb +170 -0
- data/test/unit/plugins/groonga/test_column_remove.rb +98 -0
- data/test/unit/plugins/groonga/test_column_rename.rb +105 -0
- data/test/unit/plugins/groonga/test_delete.rb +127 -0
- data/test/unit/plugins/groonga/test_table_create.rb +147 -0
- data/test/unit/plugins/groonga/test_table_list.rb +184 -0
- data/test/unit/plugins/groonga/test_table_remove.rb +61 -0
- data/test/unit/plugins/search/planner/test_basic.rb +120 -0
- data/test/unit/plugins/search/planner/test_group_by.rb +573 -0
- data/test/unit/plugins/search/planner/test_output.rb +388 -0
- data/test/unit/plugins/search/planner/test_sort_by.rb +938 -0
- data/test/unit/plugins/search/test_collector.rb +806 -0
- data/test/unit/plugins/search/test_handler.rb +930 -0
- data/test/unit/plugins/search/test_planner.rb +174 -0
- data/test/unit/plugins/test_basic.rb +510 -0
- data/test/unit/plugins/test_groonga.rb +70 -0
- data/test/unit/plugins/test_watch.rb +211 -0
- data/test/unit/run-test.rb +56 -0
- data/test/unit/test_catalog_generator.rb +93 -0
- data/test/unit/test_message_matcher.rb +160 -0
- data/test/unit/test_schema_applier.rb +59 -0
- data/test/unit/test_sweeper.rb +95 -0
- data/test/unit/test_watch_schema.rb +57 -0
- data/test/unit/test_watcher.rb +336 -0
- metadata +759 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "groonga/command/column-list"
|
17
|
+
|
18
|
+
require "droonga/plugin"
|
19
|
+
require "droonga/plugins/groonga/generic_command"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
module Plugins
|
23
|
+
module Groonga
|
24
|
+
module ColumnList
|
25
|
+
HEADER = [
|
26
|
+
["id", "UInt32"],
|
27
|
+
["name", "ShortText"],
|
28
|
+
["path", "ShortText"],
|
29
|
+
["type", "ShortText"],
|
30
|
+
["flags", "ShortText"],
|
31
|
+
["domain", "ShortText"],
|
32
|
+
["range", "ShortText"],
|
33
|
+
["source", "ShortText"],
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
class Command < GenericCommand
|
37
|
+
def process_request(request)
|
38
|
+
command_class = ::Groonga::Command.find("column_list")
|
39
|
+
@command = command_class.new("column_list", request)
|
40
|
+
|
41
|
+
table_name = valid_table_name("table")
|
42
|
+
|
43
|
+
columns = list_columns(table_name)
|
44
|
+
[HEADER, *columns]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def list_columns(table_name)
|
49
|
+
table = @context[table_name]
|
50
|
+
table.columns.collect do |column|
|
51
|
+
format_column(column)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def format_column(column)
|
56
|
+
[
|
57
|
+
column.id,
|
58
|
+
column.local_name,
|
59
|
+
column.path,
|
60
|
+
column_type(column),
|
61
|
+
column_flags(column),
|
62
|
+
column.domain.name,
|
63
|
+
column.range.name,
|
64
|
+
column_source(column),
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
def column_type(column)
|
69
|
+
case column
|
70
|
+
when ::Groonga::FixSizeColumn
|
71
|
+
"fix"
|
72
|
+
when ::Groonga::VariableSizeColumn
|
73
|
+
"var"
|
74
|
+
when ::Groonga::IndexColumn
|
75
|
+
"index"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def column_flags(column)
|
80
|
+
flags = []
|
81
|
+
if column.is_a?(::Groonga::IndexColumn)
|
82
|
+
flags << "COLUMN_INDEX"
|
83
|
+
flags << "WITH_SECTION" if column.with_section?
|
84
|
+
flags << "WITH_WEIGHT" if column.with_weight?
|
85
|
+
flags << "WITH_POSITION" if column.with_position?
|
86
|
+
else
|
87
|
+
if column.scalar?
|
88
|
+
flags << "COLUMN_SCALAR"
|
89
|
+
elsif column.vector?
|
90
|
+
flags << "COLUMN_VECTOR"
|
91
|
+
end
|
92
|
+
flags << "WITH_WEIGHT" if column.with_weight?
|
93
|
+
end
|
94
|
+
flags.join('|')
|
95
|
+
end
|
96
|
+
|
97
|
+
def column_source(column)
|
98
|
+
return [] unless column.is_a?(::Groonga::IndexColumn)
|
99
|
+
column.sources.collect do |source|
|
100
|
+
if source.is_a?(::Groonga::Table)
|
101
|
+
"_key"
|
102
|
+
else
|
103
|
+
source.local_name
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class Handler < Droonga::Handler
|
110
|
+
def handle(message)
|
111
|
+
command = Command.new(@context)
|
112
|
+
command.execute(message.request)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Groonga.define_single_step do |step|
|
117
|
+
step.name = "column_list"
|
118
|
+
step.handler = Handler
|
119
|
+
step.collector = Collectors::Or
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "groonga/command/column-remove"
|
17
|
+
|
18
|
+
require "droonga/plugin"
|
19
|
+
require "droonga/plugins/groonga/generic_command"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
module Plugins
|
23
|
+
module Groonga
|
24
|
+
module ColumnRemove
|
25
|
+
class Command < GenericCommand
|
26
|
+
def process_request(request)
|
27
|
+
command_class = ::Groonga::Command.find("column_remove")
|
28
|
+
@command = command_class.new("column_remove", request)
|
29
|
+
|
30
|
+
table_name = valid_table_name("table")
|
31
|
+
column_name = valid_column_name("name", table_name)
|
32
|
+
|
33
|
+
remove_column(table_name, column_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def remove_column(table_name, column_name)
|
38
|
+
::Groonga::Schema.define(:context => @context) do |schema|
|
39
|
+
schema.change_table(table_name) do |table|
|
40
|
+
table.remove_column(column_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Handler < Droonga::Handler
|
48
|
+
action.synchronous = true
|
49
|
+
|
50
|
+
def handle(message)
|
51
|
+
command = Command.new(@context)
|
52
|
+
command.execute(message.request)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Groonga.define_single_step do |step|
|
57
|
+
step.name = "column_remove"
|
58
|
+
step.write = true
|
59
|
+
step.handler = Handler
|
60
|
+
step.collector = Collectors::Or
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "groonga/command/column-rename"
|
17
|
+
|
18
|
+
require "droonga/plugin"
|
19
|
+
require "droonga/plugins/groonga/generic_command"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
module Plugins
|
23
|
+
module Groonga
|
24
|
+
module ColumnRename
|
25
|
+
class Command < GenericCommand
|
26
|
+
def process_request(request)
|
27
|
+
command_class = ::Groonga::Command.find("column_rename")
|
28
|
+
@command = command_class.new("column_rename", request)
|
29
|
+
|
30
|
+
table_name = valid_table_name("table")
|
31
|
+
column_name = valid_column_name("name", table_name)
|
32
|
+
|
33
|
+
new_name = @command["new_name"]
|
34
|
+
|
35
|
+
rename_column(table_name, column_name, new_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def rename_column(table_name, column_name, new_name)
|
40
|
+
::Groonga::Schema.define(:context => @context) do |schema|
|
41
|
+
schema.change_table(table_name) do |table|
|
42
|
+
table.rename_column(column_name, new_name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Handler < Droonga::Handler
|
50
|
+
action.synchronous = true
|
51
|
+
|
52
|
+
def handle(message)
|
53
|
+
command = Command.new(@context)
|
54
|
+
command.execute(message.request)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Groonga.define_single_step do |step|
|
59
|
+
step.name = "column_rename"
|
60
|
+
step.write = true
|
61
|
+
step.handler = Handler
|
62
|
+
step.collector = Collectors::Or
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,117 @@
|
|
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 "groonga/command/delete"
|
17
|
+
|
18
|
+
require "droonga/plugin"
|
19
|
+
require "droonga/plugins/groonga/generic_command"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
module Plugins
|
23
|
+
module Groonga
|
24
|
+
module Delete
|
25
|
+
class Command < GenericCommand
|
26
|
+
def process_request(request)
|
27
|
+
command_class = ::Groonga::Command.find("delete")
|
28
|
+
@command = command_class.new("delete", request)
|
29
|
+
|
30
|
+
table_name = valid_table_name("table")
|
31
|
+
|
32
|
+
key = @command["key"]
|
33
|
+
id = @command["id"]
|
34
|
+
filter = @command["filter"]
|
35
|
+
|
36
|
+
validate_parameters(key, id, filter)
|
37
|
+
|
38
|
+
table = @context[table_name]
|
39
|
+
if key
|
40
|
+
delete_record_by_key(table, key)
|
41
|
+
elsif id
|
42
|
+
delete_record_by_id(table, id)
|
43
|
+
else
|
44
|
+
delete_record_by_filter(table, filter)
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def validate_parameters(key, id, filter)
|
52
|
+
if key.nil? and id.nil? and filter.nil?
|
53
|
+
message = "you must specify \"key\", \"id\", or \"filter\""
|
54
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
55
|
+
:message => message,
|
56
|
+
:result => false)
|
57
|
+
end
|
58
|
+
|
59
|
+
count = 0
|
60
|
+
count += 1 if key
|
61
|
+
count += 1 if id
|
62
|
+
count += 1 if filter
|
63
|
+
if count > 1
|
64
|
+
message = "\"key\", \"id\", and \"filter\" are exclusive"
|
65
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
66
|
+
:message => message,
|
67
|
+
:result => false)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_record_by_key(table, key)
|
72
|
+
record = table[key]
|
73
|
+
record.delete unless record.nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
def delete_record_by_id(table, id)
|
77
|
+
record = table[id.to_i]
|
78
|
+
record.delete if record and record.valid_id?
|
79
|
+
end
|
80
|
+
|
81
|
+
def delete_record_by_filter(table, filter)
|
82
|
+
condition = ::Groonga::Expression.new(:context => @context)
|
83
|
+
condition.define_variable(:domain => table)
|
84
|
+
begin
|
85
|
+
condition.parse(filter, :syntax => :script)
|
86
|
+
rescue ::Groonga::SyntaxError
|
87
|
+
message = "syntax error in filter: <#{filter}>"
|
88
|
+
raise CommandError.new(:status => Status::SYNTAX_ERROR,
|
89
|
+
:message => message,
|
90
|
+
:result => false)
|
91
|
+
end
|
92
|
+
records = table.select(condition)
|
93
|
+
records.each do |record|
|
94
|
+
record.key.delete
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Handler < Droonga::Handler
|
100
|
+
action.synchronous = true
|
101
|
+
|
102
|
+
def handle(message)
|
103
|
+
command = Command.new(@context)
|
104
|
+
command.execute(message.request)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
Groonga.define_single_step do |step|
|
109
|
+
step.name = "delete"
|
110
|
+
step.write = true
|
111
|
+
step.handler = Handler
|
112
|
+
step.collector = Collectors::Or
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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 "groonga"
|
17
|
+
|
18
|
+
module Droonga
|
19
|
+
module Plugins
|
20
|
+
module Groonga
|
21
|
+
module Status
|
22
|
+
SUCCESS = 0
|
23
|
+
INVALID_ARGUMENT = -22
|
24
|
+
SYNTAX_ERROR = -63
|
25
|
+
end
|
26
|
+
|
27
|
+
class GenericCommand
|
28
|
+
class CommandError < StandardError
|
29
|
+
attr_reader :status, :message, :result
|
30
|
+
|
31
|
+
def initialize(params={})
|
32
|
+
@status = params[:status]
|
33
|
+
@message = params[:message]
|
34
|
+
@result = params[:result]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(context)
|
39
|
+
@context = context
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(request)
|
43
|
+
@start_time = Time.now.to_f
|
44
|
+
result = process_request(request)
|
45
|
+
[header(Status::SUCCESS), result]
|
46
|
+
rescue CommandError => error
|
47
|
+
unless error.result.nil?
|
48
|
+
[header(error.status, error.message), error.result]
|
49
|
+
else
|
50
|
+
[header(error.status, error.message)]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def header(return_code, error_message="")
|
56
|
+
elapsed_time = Time.now.to_f - @start_time
|
57
|
+
header = [return_code, @start_time, elapsed_time]
|
58
|
+
header.push(error_message) unless error_message.empty?
|
59
|
+
header
|
60
|
+
end
|
61
|
+
|
62
|
+
def valid_table_name(name)
|
63
|
+
table_name = @command[name]
|
64
|
+
|
65
|
+
if table_name.nil?
|
66
|
+
message = "you must specify table via \"#{name}\""
|
67
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
68
|
+
:message => message,
|
69
|
+
:result => false)
|
70
|
+
end
|
71
|
+
|
72
|
+
if @context[table_name].nil?
|
73
|
+
message = "table not found: <#{table_name.to_s}>"
|
74
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
75
|
+
:message => message,
|
76
|
+
:result => false)
|
77
|
+
end
|
78
|
+
|
79
|
+
table_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def valid_column_name(name, table_name)
|
83
|
+
column_name = @command[name]
|
84
|
+
|
85
|
+
if column_name.nil?
|
86
|
+
message = "you must specify column via \"#{name}\""
|
87
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
88
|
+
:message => message,
|
89
|
+
:result => false)
|
90
|
+
end
|
91
|
+
|
92
|
+
if @context[table_name].column(column_name).nil?
|
93
|
+
message = "column not found: <#{column_name.to_s}> in " +
|
94
|
+
"<#{table_name.to_s}>"
|
95
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
96
|
+
:message => message,
|
97
|
+
:result => false)
|
98
|
+
end
|
99
|
+
|
100
|
+
column_name
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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"
|
17
|
+
|
18
|
+
module Droonga
|
19
|
+
module Plugins
|
20
|
+
module Groonga
|
21
|
+
module Generic
|
22
|
+
class Adapter < Droonga::Adapter
|
23
|
+
groonga_commands = [
|
24
|
+
"table_create",
|
25
|
+
"table_remove",
|
26
|
+
"table_list",
|
27
|
+
"column_create",
|
28
|
+
"column_remove",
|
29
|
+
"column_rename",
|
30
|
+
"column_list",
|
31
|
+
"delete",
|
32
|
+
]
|
33
|
+
input_message.pattern = ["type", :in, groonga_commands]
|
34
|
+
output_message.pattern = ["body.result", :exist]
|
35
|
+
|
36
|
+
def adapt_output(output_message)
|
37
|
+
output_message.body = output_message.body["result"]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|