groonga-client 0.5.9 → 0.6.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 +4 -4
- data/doc/text/news.md +14 -0
- data/lib/groonga/client/command-line/groonga-client.rb +131 -0
- data/lib/groonga/client/response/base.rb +8 -4
- data/lib/groonga/client/version.rb +2 -2
- data/test/response/test-base.rb +14 -1
- metadata +28 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaec3aab0752df6b5832fe16cb3c79d107103636b06a603ecb2e453bd6e29bec
|
4
|
+
data.tar.gz: cc03ea25d9b87599a6fc10cc553716c3bd7e0b885b2887f7a414b0377490e37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a4c67ddfa8bb7f401ff0cd5f49d852f3f279966c3839379ae0ed0f29629b8402ae7b14a87087f263440b8ee0365eb646688a8a3ad7b1cc9979d9ddd3bc61d1
|
7
|
+
data.tar.gz: 86c7edc062f853a4d56e18b0b43477f6317630471de314d4952ab8dd7b9a85146180ce8d5e93ce7f687e0345ec6a26f938846409b3ad3bdcd45677ec4e0029f2
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.6.0 - 2018-08-30
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* `groonga-client`:
|
8
|
+
|
9
|
+
* Added `--target-command` option.
|
10
|
+
|
11
|
+
* Added `--target-table` option.
|
12
|
+
|
13
|
+
* Added `--target-column` option.
|
14
|
+
|
15
|
+
* Added support for JSONP.
|
16
|
+
|
3
17
|
## 0.5.9 - 2018-07-13
|
4
18
|
|
5
19
|
### Improvements
|
@@ -34,6 +34,9 @@ module Groonga
|
|
34
34
|
@runner_options = {
|
35
35
|
:split_load_chunk_size => 10000,
|
36
36
|
:generate_request_id => false,
|
37
|
+
:target_commands => [],
|
38
|
+
:target_tables => [],
|
39
|
+
:target_columns => [],
|
37
40
|
}
|
38
41
|
end
|
39
42
|
|
@@ -108,6 +111,39 @@ module Groonga
|
|
108
111
|
"(#{@chunk})") do |boolean|
|
109
112
|
@chunk = boolean
|
110
113
|
end
|
114
|
+
|
115
|
+
parser.on("--target-command=COMMAND",
|
116
|
+
"Add COMMAND as target commands",
|
117
|
+
"You can specify multiple times",
|
118
|
+
"If COMMAND is /.../,",
|
119
|
+
"it's treated as a regular expression") do |command|
|
120
|
+
add_target(@runner_options[:target_commands], command)
|
121
|
+
end
|
122
|
+
|
123
|
+
parser.on("--target-table=TABLE",
|
124
|
+
"Add TABLE as target tables",
|
125
|
+
"You can specify multiple times",
|
126
|
+
"If TABLE is /.../,",
|
127
|
+
"it's treated as a regular expression") do |table|
|
128
|
+
add_target(@runner_options[:target_tables], table)
|
129
|
+
end
|
130
|
+
|
131
|
+
parser.on("--target-column=COLUMN",
|
132
|
+
"Add COLUMN as target columns",
|
133
|
+
"You can specify multiple times",
|
134
|
+
"If COLUMN is /.../,",
|
135
|
+
"it's treated as a regular expression") do |column|
|
136
|
+
add_target(@runner_options[:target_columns], column)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_target(targets, target)
|
141
|
+
if /\A\\(.+?)\\(i)?\z/ =~ target
|
142
|
+
pattern = Regexp.new($1, $2 == "i")
|
143
|
+
targets << pattern
|
144
|
+
else
|
145
|
+
targets << target
|
146
|
+
end
|
111
147
|
end
|
112
148
|
|
113
149
|
class Runner
|
@@ -115,6 +151,9 @@ module Groonga
|
|
115
151
|
@client = client
|
116
152
|
@split_load_chunk_size = options[:split_load_chunk_size] || 10000
|
117
153
|
@generate_request_id = options[:generate_request_id]
|
154
|
+
@target_commands = options[:target_commands]
|
155
|
+
@target_tables = options[:target_tables]
|
156
|
+
@target_columns = options[:target_columns]
|
118
157
|
@load_values = []
|
119
158
|
@parser = create_command_parser
|
120
159
|
end
|
@@ -188,6 +227,12 @@ module Groonga
|
|
188
227
|
end
|
189
228
|
|
190
229
|
def run_command(command)
|
230
|
+
return unless target_command?(command)
|
231
|
+
return unless target_table?(command)
|
232
|
+
return unless target_column?(command)
|
233
|
+
|
234
|
+
command = Marshal.load(Marshal.dump(command))
|
235
|
+
apply_target_columns(command)
|
191
236
|
command[:request_id] ||= SecureRandom.uuid if @generate_request_id
|
192
237
|
response = @client.execute(command)
|
193
238
|
case command.output_type
|
@@ -199,6 +244,92 @@ module Groonga
|
|
199
244
|
puts(response.body)
|
200
245
|
end
|
201
246
|
end
|
247
|
+
|
248
|
+
def target_command?(command)
|
249
|
+
return true if @target_commands.empty?
|
250
|
+
|
251
|
+
@target_commands.any? do |name|
|
252
|
+
name === command.command_name
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def target_table?(command)
|
257
|
+
return true if @target_tables.empty?
|
258
|
+
|
259
|
+
target = nil
|
260
|
+
case command.command_name
|
261
|
+
when "load", "column_create", "select"
|
262
|
+
target = command.table
|
263
|
+
when "table_create", "table_remove"
|
264
|
+
target = command.name
|
265
|
+
end
|
266
|
+
return true if target.nil?
|
267
|
+
|
268
|
+
@target_tables.any? do |name|
|
269
|
+
name === target
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def target_column?(command)
|
274
|
+
return true if @target_columns.empty?
|
275
|
+
|
276
|
+
target = nil
|
277
|
+
case command.command_name
|
278
|
+
when "column_create"
|
279
|
+
target = command.name
|
280
|
+
end
|
281
|
+
return true if target.nil?
|
282
|
+
|
283
|
+
@target_columns.any? do |name|
|
284
|
+
name === target
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def apply_target_columns(command)
|
289
|
+
return if @target_columns.empty?
|
290
|
+
|
291
|
+
values = command[:values]
|
292
|
+
return if values.nil?
|
293
|
+
|
294
|
+
command = command.dup
|
295
|
+
|
296
|
+
values = JSON.parse(values)
|
297
|
+
columns = command[:columns]
|
298
|
+
if columns
|
299
|
+
columns = columns.split(/\s*,\s*/)
|
300
|
+
target_indexes = []
|
301
|
+
new_columns = []
|
302
|
+
columns.each_with_index do |column, i|
|
303
|
+
if load_target_column?(column)
|
304
|
+
target_indexes << i
|
305
|
+
new_columns << column
|
306
|
+
end
|
307
|
+
end
|
308
|
+
command[:columns] = new_columns.join(",")
|
309
|
+
new_values = values.collect do |value|
|
310
|
+
target_indexes.collect do |i|
|
311
|
+
value[i]
|
312
|
+
end
|
313
|
+
end
|
314
|
+
command[:values] = JSON.generate(new_values)
|
315
|
+
else
|
316
|
+
new_values = values.collect do |value|
|
317
|
+
new_value = {}
|
318
|
+
value.each do |key, value|
|
319
|
+
if load_target_column?(key)
|
320
|
+
new_value[key] = value
|
321
|
+
end
|
322
|
+
end
|
323
|
+
new_value
|
324
|
+
end
|
325
|
+
command[:values] = JSON.generate(new_values)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def load_target_column?(column)
|
330
|
+
column == "_key" or
|
331
|
+
@target_columns.any? {|name| name === column}
|
332
|
+
end
|
202
333
|
end
|
203
334
|
|
204
335
|
class BareREPL
|
@@ -1,7 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2018 Kouhei Sutou <kou@clear-code.com>
|
5
3
|
#
|
6
4
|
# This library is free software; you can redistribute it and/or
|
7
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -67,7 +65,13 @@ module Groonga
|
|
67
65
|
return_code = nil
|
68
66
|
case command.output_type
|
69
67
|
when :json
|
70
|
-
|
68
|
+
callback = command["callback"]
|
69
|
+
if callback and
|
70
|
+
/\A#{Regexp.escape(callback)}\((.+)\);\z/ =~ raw_response
|
71
|
+
response = JSON.parse($1)
|
72
|
+
else
|
73
|
+
response = JSON.parse(raw_response)
|
74
|
+
end
|
71
75
|
if response.is_a?(::Array)
|
72
76
|
header, body = response
|
73
77
|
return_code = header[0] if header
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013-
|
1
|
+
# Copyright (C) 2013-2018 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
|
class Client
|
19
|
-
VERSION = "0.
|
19
|
+
VERSION = "0.6.0"
|
20
20
|
end
|
21
21
|
end
|
data/test/response/test-base.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2014-2018 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
|
@@ -210,4 +210,17 @@ class TestResponseBase < Test::Unit::TestCase
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
class TestParse < self
|
215
|
+
def test_jsonp
|
216
|
+
command = Groonga::Command::Base.new("status", {"callback" => "a"})
|
217
|
+
response = [
|
218
|
+
[0, 1396012478, 0.00050806999206543],
|
219
|
+
{"start_time" => 1396012478},
|
220
|
+
]
|
221
|
+
raw_response = "a(#{response.to_json});"
|
222
|
+
response = Groonga::Client::Response::Base.parse(command, raw_response)
|
223
|
+
assert_equal(1396012478, response.body["start_time"])
|
224
|
+
end
|
225
|
+
end
|
213
226
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Haruka Yoshihara
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -161,9 +161,9 @@ email:
|
|
161
161
|
- kou@clear-code.com
|
162
162
|
- tfortress58@gmail.com
|
163
163
|
executables:
|
164
|
+
- groonga-client
|
164
165
|
- groonga-client-index-check
|
165
166
|
- groonga-client-index-recreate
|
166
|
-
- groonga-client
|
167
167
|
extensions: []
|
168
168
|
extra_rdoc_files: []
|
169
169
|
files:
|
@@ -283,42 +283,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
283
|
version: '0'
|
284
284
|
requirements: []
|
285
285
|
rubyforge_project:
|
286
|
-
rubygems_version:
|
286
|
+
rubygems_version: 3.0.0.beta1
|
287
287
|
signing_key:
|
288
288
|
specification_version: 4
|
289
289
|
summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
|
290
290
|
with pure Ruby. You can use it without Groonga.
|
291
291
|
test_files:
|
292
|
-
- test/test-client.rb
|
293
|
-
- test/command-line/test-index-check.rb
|
294
|
-
- test/command-line/helper.rb
|
295
|
-
- test/command-line/test-index-recreate.rb
|
296
292
|
- test/test-script-syntax.rb
|
297
|
-
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
298
|
-
- test/request/select/test-filter.rb
|
299
|
-
- test/request/select/test-sort-keys-parameter.rb
|
300
|
-
- test/request/select/test-output-columns-parameter.rb
|
301
|
-
- test/request/select/test-values-parameter.rb
|
302
|
-
- test/request/select/test-scorer.rb
|
303
|
-
- test/request/test-merger.rb
|
304
|
-
- test/request/test-generic.rb
|
305
|
-
- test/request/test-select.rb
|
306
|
-
- test/test-command.rb
|
307
|
-
- test/protocol/test-gqtp.rb
|
308
293
|
- test/protocol/test-http.rb
|
309
|
-
- test/
|
310
|
-
- test/response/test-
|
294
|
+
- test/protocol/test-gqtp.rb
|
295
|
+
- test/response/test-schema.rb
|
311
296
|
- test/response/test-select-tsv.rb
|
312
|
-
- test/response/test-load.rb
|
313
|
-
- test/response/test-column-list.rb
|
314
|
-
- test/response/helper.rb
|
315
297
|
- test/response/test-error.rb
|
316
|
-
- test/response/test-table-
|
317
|
-
- test/response/test-status.rb
|
298
|
+
- test/response/test-table-remove.rb
|
318
299
|
- test/response/test-select-xml.rb
|
319
|
-
- test/response/test-schema.rb
|
320
300
|
- test/response/test-select-command-version3.rb
|
301
|
+
- test/response/test-table-list.rb
|
302
|
+
- test/response/test-column-list.rb
|
303
|
+
- test/response/test-load.rb
|
304
|
+
- test/response/helper.rb
|
305
|
+
- test/response/test-base.rb
|
321
306
|
- test/response/test-select-command-version1.rb
|
307
|
+
- test/response/test-status.rb
|
322
308
|
- test/response/test-table-create.rb
|
323
|
-
- test/response/test-table-remove.rb
|
324
309
|
- test/results/test-table-list.rb
|
310
|
+
- test/test-command.rb
|
311
|
+
- test/run-test.rb
|
312
|
+
- test/request/test-generic.rb
|
313
|
+
- test/request/select/test-values-parameter.rb
|
314
|
+
- test/request/select/test-output-columns-parameter.rb
|
315
|
+
- test/request/select/test-scorer.rb
|
316
|
+
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
317
|
+
- test/request/select/test-filter.rb
|
318
|
+
- test/request/select/test-sort-keys-parameter.rb
|
319
|
+
- test/request/test-select.rb
|
320
|
+
- test/request/test-merger.rb
|
321
|
+
- test/test-client.rb
|
322
|
+
- test/command-line/test-index-recreate.rb
|
323
|
+
- test/command-line/helper.rb
|
324
|
+
- test/command-line/test-index-check.rb
|