groonga-command 1.3.9 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/doc/text/news.md +8 -0
- data/lib/groonga/command/base.rb +7 -0
- data/lib/groonga/command/format/elasticsearch.rb +90 -0
- data/lib/groonga/command/version.rb +2 -2
- data/test/command/test-base.rb +132 -0
- metadata +45 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94a17f5c7b56db7a29320cb7af65395183b7a43c
|
4
|
+
data.tar.gz: 5a199858fd2c1a291bc6fdc4f0e5d76518f19011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0107882a318b6518b8825d68c9c38958b9a98ef3f0e110de7985c848425046e3202ae13a32670353bb99c34a3ac685b697248dabe25ce2747fe3daff0a907bc7'
|
7
|
+
data.tar.gz: 2f83719bcb481a8a745deca1f3c5337f1f4e6c341f34299f3d03c740e7f9e9a458c07cfe7928cc2c5c30444830ab90ba25549011c09e919915ca082496a2e013
|
data/doc/text/news.md
CHANGED
data/lib/groonga/command/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright (C) 2012-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
# Copyright (C) 2019 Yasuhiro Horimoto <horimoto@clear-code.com>
|
2
3
|
#
|
3
4
|
# This library is free software; you can redistribute it and/or
|
4
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -16,6 +17,7 @@
|
|
16
17
|
|
17
18
|
require "groonga/command/format/uri"
|
18
19
|
require "groonga/command/format/command"
|
20
|
+
require "groonga/command/format/elasticsearch"
|
19
21
|
|
20
22
|
module Groonga
|
21
23
|
module Command
|
@@ -153,6 +155,11 @@ module Groonga
|
|
153
155
|
format.command_line(options)
|
154
156
|
end
|
155
157
|
|
158
|
+
def to_elasticsearch_format(options={})
|
159
|
+
format = Format::Elasticsearch.new(@command_name, normalized_arguments)
|
160
|
+
format.json(options)
|
161
|
+
end
|
162
|
+
|
156
163
|
def to_s
|
157
164
|
if uri_format?
|
158
165
|
to_uri_format
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (C) 2019 Yasuhiro Horimoto <horimoto@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module Groonga
|
18
|
+
module Command
|
19
|
+
module Format
|
20
|
+
class Elasticsearch
|
21
|
+
def initialize(name, arguments)
|
22
|
+
@name = name
|
23
|
+
@arguments = arguments
|
24
|
+
end
|
25
|
+
|
26
|
+
def json(options={})
|
27
|
+
return nil unless @name == "load"
|
28
|
+
|
29
|
+
components = []
|
30
|
+
elasticsearch_version = options[:version] || 5
|
31
|
+
|
32
|
+
sorted_arguments = @arguments.sort_by(&:first)
|
33
|
+
sorted_arguments.each do |name, value|
|
34
|
+
case name
|
35
|
+
when :table
|
36
|
+
case elasticsearch_version
|
37
|
+
when 7
|
38
|
+
header = {
|
39
|
+
"index" => {
|
40
|
+
"_index" => value.downcase,
|
41
|
+
"_type"=>"_doc",
|
42
|
+
}
|
43
|
+
}
|
44
|
+
when 8
|
45
|
+
header = {
|
46
|
+
"index" => {
|
47
|
+
"_index" => value.downcase,
|
48
|
+
}
|
49
|
+
}
|
50
|
+
else
|
51
|
+
# Version 5.x or 6.x
|
52
|
+
header = {
|
53
|
+
"index" => {
|
54
|
+
"_index" => value.downcase,
|
55
|
+
"_type" => "groonga",
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
components << JSON.generate(header)
|
60
|
+
when :values
|
61
|
+
record = JSON.parse(value)
|
62
|
+
|
63
|
+
if record[0].is_a?(::Array)
|
64
|
+
column_names = nil
|
65
|
+
|
66
|
+
record.each do |load_value|
|
67
|
+
if column_names.nil?
|
68
|
+
column_names = load_value
|
69
|
+
next
|
70
|
+
end
|
71
|
+
body = {}
|
72
|
+
column_values = load_value
|
73
|
+
column_names.zip(column_values) do |column_name, column_value|
|
74
|
+
body[column_name] = column_value
|
75
|
+
end
|
76
|
+
components << JSON.generate(body)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
record.each do |load_value|
|
80
|
+
components << JSON.generate(load_value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
components.join("\n")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2012-
|
1
|
+
# Copyright (C) 2012-2019 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -16,6 +16,6 @@
|
|
16
16
|
|
17
17
|
module Groonga
|
18
18
|
module Command
|
19
|
-
VERSION = "1.
|
19
|
+
VERSION = "1.4.0"
|
20
20
|
end
|
21
21
|
end
|
data/test/command/test-base.rb
CHANGED
@@ -122,6 +122,138 @@ select \\
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
+
class CovnertToElasticsearchFormatTest < self
|
126
|
+
sub_test_case("non target command") do
|
127
|
+
def test_select_command
|
128
|
+
select = Groonga::Command::Base.new("select",
|
129
|
+
:table => "Users",
|
130
|
+
:filter => "age<=30",
|
131
|
+
:output_type => "json")
|
132
|
+
assert_equal(nil,
|
133
|
+
select.to_elasticsearch_format)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
sub_test_case("single record") do
|
138
|
+
def test_brackets_format
|
139
|
+
load = Groonga::Command::Base.new("load",
|
140
|
+
:table => "Site",
|
141
|
+
:values => <<-VALUES)
|
142
|
+
[
|
143
|
+
["_key","title"],
|
144
|
+
["http://example.org/","This is test record 1!"]
|
145
|
+
]
|
146
|
+
VALUES
|
147
|
+
|
148
|
+
expected = <<-OUTPUT.chomp
|
149
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
150
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
151
|
+
OUTPUT
|
152
|
+
|
153
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_curly_brackets_format
|
157
|
+
load = Groonga::Command::Base.new("load",
|
158
|
+
:table => "Site",
|
159
|
+
:values => <<-VALUES)
|
160
|
+
[
|
161
|
+
{"_key": "http://example.org/", "title": "This is test record 1!"}
|
162
|
+
]
|
163
|
+
VALUES
|
164
|
+
|
165
|
+
expected = <<-OUTPUT.chomp
|
166
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
167
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
168
|
+
OUTPUT
|
169
|
+
|
170
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
sub_test_case("multiple records") do
|
175
|
+
def test_brackets_format
|
176
|
+
load = Groonga::Command::Base.new("load",
|
177
|
+
:table => "Site",
|
178
|
+
:values => <<-VALUES)
|
179
|
+
[
|
180
|
+
["_key","title"],
|
181
|
+
["http://example.org/","This is test record 1!"],
|
182
|
+
["http://example.net/","This is test record 2!"]
|
183
|
+
]
|
184
|
+
VALUES
|
185
|
+
|
186
|
+
expected = <<-OUTPUT.chomp
|
187
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
188
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
189
|
+
{"_key":"http://example.net/","title":"This is test record 2!"}
|
190
|
+
OUTPUT
|
191
|
+
|
192
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_curly_brackets_format
|
196
|
+
load = Groonga::Command::Base.new("load",
|
197
|
+
:table => "Site",
|
198
|
+
:values => <<-VALUES)
|
199
|
+
[
|
200
|
+
{"_key": "http://example.org/", "title": "This is test record 1!"},
|
201
|
+
{"_key": "http://example.net/", "title": "This is test record 2!"}
|
202
|
+
]
|
203
|
+
VALUES
|
204
|
+
|
205
|
+
expected = <<-OUTPUT.chomp
|
206
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
207
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
208
|
+
{"_key":"http://example.net/","title":"This is test record 2!"}
|
209
|
+
OUTPUT
|
210
|
+
|
211
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def setup
|
216
|
+
@load = Groonga::Command::Base.new("load",
|
217
|
+
:table => "Site",
|
218
|
+
:values => <<-VALUES)
|
219
|
+
[
|
220
|
+
["_key","title"],
|
221
|
+
["http://example.org/","This is test record 1!"]
|
222
|
+
]
|
223
|
+
VALUES
|
224
|
+
end
|
225
|
+
|
226
|
+
sub_test_case(":version") do
|
227
|
+
def test_5
|
228
|
+
assert_equal(<<-REQUESTS.chomp, @load.to_elasticsearch_format(:version => 5))
|
229
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
230
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
231
|
+
REQUESTS
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_6
|
235
|
+
assert_equal(<<-REQUESTS.chomp, @load.to_elasticsearch_format(:version => 6))
|
236
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
237
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
238
|
+
REQUESTS
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_7
|
242
|
+
assert_equal(<<-REQUESTS.chomp, @load.to_elasticsearch_format(:version => 7))
|
243
|
+
{"index":{"_index":"site","_type":"_doc"}}
|
244
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
245
|
+
REQUESTS
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_8
|
249
|
+
assert_equal(<<-REQUESTS.chomp, @load.to_elasticsearch_format(:version => 8))
|
250
|
+
{"index":{"_index":"site"}}
|
251
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
252
|
+
REQUESTS
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
125
257
|
sub_test_case("#to_s") do
|
126
258
|
def setup
|
127
259
|
@table = "Users"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/groonga/command/dump.rb
|
151
151
|
- lib/groonga/command/error.rb
|
152
152
|
- lib/groonga/command/format/command.rb
|
153
|
+
- lib/groonga/command/format/elasticsearch.rb
|
153
154
|
- lib/groonga/command/format/uri.rb
|
154
155
|
- lib/groonga/command/get.rb
|
155
156
|
- lib/groonga/command/index-column-diff.rb
|
@@ -271,65 +272,65 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
272
|
version: '0'
|
272
273
|
requirements: []
|
273
274
|
rubyforge_project:
|
274
|
-
rubygems_version: 2.
|
275
|
+
rubygems_version: 2.5.2.1
|
275
276
|
signing_key:
|
276
277
|
specification_version: 4
|
277
278
|
summary: Groonga-command is a library that represents [Groonga](http://groonga.org/)'s
|
278
279
|
command. You can write a program that handle Groonga's command by using groonga-command.
|
279
280
|
test_files:
|
280
281
|
- test/run-test.rb
|
281
|
-
- test/command
|
282
|
-
- test/command/test-
|
283
|
-
- test/command/test-
|
284
|
-
- test/command/test-io-flush.rb
|
285
|
-
- test/command/test-base.rb
|
286
|
-
- test/command/test-column-remove.rb
|
282
|
+
- test/groonga-command-test-utils.rb
|
283
|
+
- test/command/test-query-log-flags-add.rb
|
284
|
+
- test/command/test-log-put.rb
|
287
285
|
- test/command/test-column-create.rb
|
288
286
|
- test/command/test-config-get.rb
|
287
|
+
- test/command/test-logical-select.rb
|
288
|
+
- test/command/test-plugin-register.rb
|
289
|
+
- test/command/test-io-flush.rb
|
290
|
+
- test/command/test-column-remove.rb
|
291
|
+
- test/command/test-query-expand.rb
|
292
|
+
- test/command/test-logical-count.rb
|
293
|
+
- test/command/test-log-level.rb
|
294
|
+
- test/command/test-shutdown.rb
|
295
|
+
- test/command/test-column-copy.rb
|
296
|
+
- test/command/test-suggest.rb
|
297
|
+
- test/command/test-get.rb
|
289
298
|
- test/command/test-index-column-diff.rb
|
299
|
+
- test/command/test-logical-shard-list.rb
|
300
|
+
- test/command/test-table-create.rb
|
290
301
|
- test/command/test-logical-table-remove.rb
|
291
302
|
- test/command/test-query-log-flags-get.rb
|
292
|
-
- test/command/test-
|
293
|
-
- test/command/test-plugin-
|
294
|
-
- test/command/test-
|
295
|
-
- test/command/test-
|
296
|
-
- test/command/test-query-log-flags-add.rb
|
303
|
+
- test/command/test-query-log-flags-set.rb
|
304
|
+
- test/command/test-plugin-unregister.rb
|
305
|
+
- test/command/test-delete.rb
|
306
|
+
- test/command/test-status.rb
|
297
307
|
- test/command/test-logical-range-filter.rb
|
308
|
+
- test/command/test-column-list.rb
|
309
|
+
- test/command/test-config-delete.rb
|
310
|
+
- test/command/test-dump.rb
|
311
|
+
- test/command/format/test-command.rb
|
312
|
+
- test/command/test-tokenize.rb
|
298
313
|
- test/command/test-table-tokenize.rb
|
299
|
-
- test/command/test-
|
314
|
+
- test/command/test-table-rename.rb
|
315
|
+
- test/command/test-object-remove.rb
|
300
316
|
- test/command/test-range-filter.rb
|
301
|
-
- test/command/test-query-log-flags-set.rb
|
302
|
-
- test/command/test-logical-shard-list.rb
|
303
|
-
- test/command/test-load.rb
|
304
|
-
- test/command/test-config-set.rb
|
305
|
-
- test/command/test-register.rb
|
306
|
-
- test/command/test-column-rename.rb
|
307
|
-
- test/command/test-config-delete.rb
|
308
|
-
- test/command/test-ruby-eval.rb
|
309
317
|
- test/command/test-table-copy.rb
|
310
|
-
- test/command/test-delete.rb
|
311
|
-
- test/command/test-column-list.rb
|
312
|
-
- test/command/test-request-cancel.rb
|
313
|
-
- test/command/test-schema.rb
|
314
|
-
- test/command/test-get.rb
|
315
|
-
- test/command/test-ruby-load.rb
|
316
318
|
- test/command/test-query-log-flags-remove.rb
|
319
|
+
- test/command/test-column-rename.rb
|
320
|
+
- test/command/test-config-set.rb
|
321
|
+
- test/command/test-thread-limit.rb
|
322
|
+
- test/command/test-select.rb
|
323
|
+
- test/command/test-reindex.rb
|
324
|
+
- test/command/test-schema.rb
|
317
325
|
- test/command/test-truncate.rb
|
318
|
-
- test/command/test-
|
319
|
-
- test/command/test-
|
326
|
+
- test/command/test-ruby-eval.rb
|
327
|
+
- test/command/test-ruby-load.rb
|
328
|
+
- test/command/test-request-cancel.rb
|
329
|
+
- test/command/test-table-list.rb
|
330
|
+
- test/command/test-load.rb
|
320
331
|
- test/command/test-object-inspect.rb
|
321
|
-
- test/command/test-
|
322
|
-
- test/command/test-
|
332
|
+
- test/command/test-register.rb
|
333
|
+
- test/command/test-base.rb
|
323
334
|
- test/command/test-object-exist.rb
|
324
|
-
- test/command/test-thread-limit.rb
|
325
|
-
- test/command/test-tokenize.rb
|
326
|
-
- test/command/test-select.rb
|
327
|
-
- test/command/test-log-put.rb
|
328
|
-
- test/command/test-log-level.rb
|
329
|
-
- test/command/test-plugin-unregister.rb
|
330
|
-
- test/command/test-table-rename.rb
|
331
335
|
- test/command/test-normalize.rb
|
332
|
-
- test/command/test-
|
333
|
-
- test/command/test-table-list.rb
|
334
|
-
- test/command/test-table-create.rb
|
335
|
-
- test/groonga-command-test-utils.rb
|
336
|
+
- test/command/test-table-remove.rb
|