groonga-client 0.5.8 → 0.5.9
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 +6 -0
- data/lib/groonga/client.rb +15 -3
- data/lib/groonga/client/command-line/groonga-client.rb +119 -3
- data/lib/groonga/client/protocol/file.rb +76 -0
- data/lib/groonga/client/protocol/http/path-resolvable.rb +6 -1
- data/lib/groonga/client/response/base.rb +44 -0
- data/lib/groonga/client/response/error.rb +42 -2
- data/lib/groonga/client/response/select.rb +72 -0
- data/lib/groonga/client/version.rb +1 -1
- data/test/response/helper.rb +5 -0
- data/test/response/test-error.rb +1 -1
- data/test/response/test-select-tsv.rb +127 -0
- data/test/test-client.rb +2 -2
- metadata +31 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16493f7abb6c08faa1f10060a64bedca44071acc4772ed06ac400a91a4b96282
|
4
|
+
data.tar.gz: 0c94271fb51d35d2758e423a7d52cacc46488ae1c6afbc9ab947b3093dedcfee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df38010cd75c8e29bd0461243ed0ce07a6cb7efe84450e2eae1e5a8612cd3237be4f00c37bda7a10bbd7016bf5be88507961016337664c988a27ee5c66487b5
|
7
|
+
data.tar.gz: 3a23a2605d9711c4e46582b5a06021a434763d7021a4bd1263be077e605ec1bdcfdfb7fd8d858e2166bd0213ec2feb24961317699a486d33c817182214c3106b
|
data/doc/text/news.md
CHANGED
data/lib/groonga/client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
2
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
|
3
3
|
#
|
4
4
|
# This library is free software; you can redistribute it and/or
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -23,6 +23,7 @@ require "groonga/client/command"
|
|
23
23
|
require "groonga/client/empty-request"
|
24
24
|
require "groonga/client/protocol/gqtp"
|
25
25
|
require "groonga/client/protocol/http"
|
26
|
+
require "groonga/client/protocol/file"
|
26
27
|
require "groonga/client/request"
|
27
28
|
|
28
29
|
module Groonga
|
@@ -100,9 +101,11 @@ module Groonga
|
|
100
101
|
@connection = Groonga::Client::Protocol::GQTP.new(url, options)
|
101
102
|
when "http", "https"
|
102
103
|
@connection = Groonga::Client::Protocol::HTTP.new(url, options)
|
104
|
+
when "file"
|
105
|
+
@connection = Groonga::Client::Protocol::File.new(url, options)
|
103
106
|
else
|
104
107
|
message = "unsupported scheme: <#{url.scheme}>: "
|
105
|
-
message << "supported: [gqtp, http, https]"
|
108
|
+
message << "supported: [gqtp, http, https, file]"
|
106
109
|
raise ArgumentError, message
|
107
110
|
end
|
108
111
|
end
|
@@ -219,7 +222,7 @@ module Groonga
|
|
219
222
|
scheme = (options.delete(:protocol) || "gqtp").to_s
|
220
223
|
host = options.delete(:host) || options.delete(:address) || "127.0.0.1"
|
221
224
|
port = options.delete(:port) || default_port(scheme)
|
222
|
-
path = options.delete(:path)
|
225
|
+
path = options.delete(:path) || default_path(scheme)
|
223
226
|
user = options.delete(:user)
|
224
227
|
password = options.delete(:password)
|
225
228
|
if user and password
|
@@ -260,6 +263,15 @@ module Groonga
|
|
260
263
|
end
|
261
264
|
end
|
262
265
|
|
266
|
+
def default_path(scheme)
|
267
|
+
case scheme
|
268
|
+
when "http", "https"
|
269
|
+
"/d/"
|
270
|
+
else
|
271
|
+
nil
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
263
275
|
def groonga_command_name?(name)
|
264
276
|
/\A[a-zA-Z][a-zA-Z\d_]+\z/ === name.to_s
|
265
277
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2015-
|
1
|
+
# Copyright (C) 2015-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
|
@@ -14,7 +14,9 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
+
require "fileutils"
|
17
18
|
require "json"
|
19
|
+
require "pathname"
|
18
20
|
require "securerandom"
|
19
21
|
|
20
22
|
require "groonga/command/parser"
|
@@ -45,8 +47,19 @@ module Groonga
|
|
45
47
|
runner = Runner.new(client, @runner_options)
|
46
48
|
|
47
49
|
if command_file_paths.empty?
|
48
|
-
$stdin.
|
49
|
-
|
50
|
+
if $stdin.tty? and $stdout.tty?
|
51
|
+
begin
|
52
|
+
require "readline"
|
53
|
+
rescue LoadError
|
54
|
+
repl = BareREPL.new(runner)
|
55
|
+
else
|
56
|
+
repl = ReadlineREPL.new(runner)
|
57
|
+
end
|
58
|
+
repl.run
|
59
|
+
else
|
60
|
+
$stdin.each_line do |line|
|
61
|
+
runner << line
|
62
|
+
end
|
50
63
|
end
|
51
64
|
else
|
52
65
|
command_file_paths.each do |command_file_path|
|
@@ -114,6 +127,17 @@ module Groonga
|
|
114
127
|
@parser.finish
|
115
128
|
end
|
116
129
|
|
130
|
+
def repl
|
131
|
+
begin
|
132
|
+
require "readline"
|
133
|
+
rescue LoadError
|
134
|
+
repl = BareREPL.new(self)
|
135
|
+
else
|
136
|
+
repl = ReadlineREPL.new(self)
|
137
|
+
repl_readline
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
117
141
|
private
|
118
142
|
def create_command_parser
|
119
143
|
parser = Groonga::Command::Parser.new
|
@@ -176,6 +200,98 @@ module Groonga
|
|
176
200
|
end
|
177
201
|
end
|
178
202
|
end
|
203
|
+
|
204
|
+
class BareREPL
|
205
|
+
def initialize(runner)
|
206
|
+
@runner = runner
|
207
|
+
end
|
208
|
+
|
209
|
+
def run
|
210
|
+
loop do
|
211
|
+
print("> ")
|
212
|
+
$stdout.flush
|
213
|
+
line = gets
|
214
|
+
break if line.nil?
|
215
|
+
@runner << line
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class ReadlineREPL
|
221
|
+
def initialize(runner)
|
222
|
+
@runner = runner
|
223
|
+
@history_path = guess_history_path
|
224
|
+
read_history
|
225
|
+
end
|
226
|
+
|
227
|
+
def run
|
228
|
+
loop do
|
229
|
+
line = Readline.readline("> ", true)
|
230
|
+
break if line.nil?
|
231
|
+
add_history(line)
|
232
|
+
@runner << line
|
233
|
+
@runner << "\n"
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
private
|
238
|
+
def guess_history_path
|
239
|
+
case RUBY_PLATFORM
|
240
|
+
when /mswin/, /mingw/
|
241
|
+
base_dir = ENV["LOCALAPPDATA"] || "~/AppData"
|
242
|
+
when /darwin/
|
243
|
+
base_dir = "~/Library/Preferences"
|
244
|
+
else
|
245
|
+
base_dir = ENV["XDG_CONFIG_HOME"] || "~/.config"
|
246
|
+
end
|
247
|
+
Pathname(base_dir).expand_path + "groonga-client" + "history.txt"
|
248
|
+
end
|
249
|
+
|
250
|
+
def read_history
|
251
|
+
if @history_path.exist?
|
252
|
+
@history_path.open do |history_file|
|
253
|
+
history_file.each_line do |line|
|
254
|
+
Readline::HISTORY << line.chomp
|
255
|
+
end
|
256
|
+
end
|
257
|
+
@history_timestamp = @history_path.mtime
|
258
|
+
else
|
259
|
+
@history_timestamp = Time.now
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def add_history(entry)
|
264
|
+
updated = history_is_updated?
|
265
|
+
|
266
|
+
if new_history_entry?(entry)
|
267
|
+
FileUtils.mkdir_p(@history_path.dirname)
|
268
|
+
@history_path.open("a") do |history_file|
|
269
|
+
history_file << entry
|
270
|
+
history_file << "\n"
|
271
|
+
end
|
272
|
+
else
|
273
|
+
Readline::HISTORY.pop
|
274
|
+
end
|
275
|
+
|
276
|
+
if updated
|
277
|
+
Readline::HISTORY.clear
|
278
|
+
read_history
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def history_is_updated?
|
283
|
+
@history_path.exist? and
|
284
|
+
@history_path.mtime > @history_timestamp
|
285
|
+
end
|
286
|
+
|
287
|
+
def new_history_entry?(entry)
|
288
|
+
return false if /\A\s*\z/ =~ entry
|
289
|
+
if Readline::HISTORY.size > 1 and Readline::HISTORY[-2] == entry
|
290
|
+
return false
|
291
|
+
end
|
292
|
+
true
|
293
|
+
end
|
294
|
+
end
|
179
295
|
end
|
180
296
|
end
|
181
297
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@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
|
+
require "groonga/client/version"
|
18
|
+
require "groonga/client/protocol/error"
|
19
|
+
|
20
|
+
module Groonga
|
21
|
+
class Client
|
22
|
+
module Protocol
|
23
|
+
class File
|
24
|
+
def initialize(url, options)
|
25
|
+
@url = url
|
26
|
+
@options = options
|
27
|
+
end
|
28
|
+
|
29
|
+
def send(command, &block)
|
30
|
+
open_pipes do |input, output, error|
|
31
|
+
options = {
|
32
|
+
:in => input[0],
|
33
|
+
:out => output[1],
|
34
|
+
:err => error[1],
|
35
|
+
}
|
36
|
+
pid = spawn("groonga", @url.path, options)
|
37
|
+
input[0].close
|
38
|
+
output[1].close
|
39
|
+
error[1].close
|
40
|
+
|
41
|
+
input[1].puts(command.to_command_format)
|
42
|
+
input[1].close
|
43
|
+
response = output[0].read
|
44
|
+
Process.waitpid(pid)
|
45
|
+
yield(response)
|
46
|
+
EmptyRequest.new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def connected?
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def close(&block)
|
55
|
+
if block_given?
|
56
|
+
yield
|
57
|
+
EmptyRequest.new
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def open_pipes
|
65
|
+
IO.pipe do |input|
|
66
|
+
IO.pipe do |output|
|
67
|
+
IO.pipe do |error|
|
68
|
+
yield(input, output, error)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -21,7 +21,12 @@ module Groonga
|
|
21
21
|
module PathResolvable
|
22
22
|
private
|
23
23
|
def resolve_path(uri, path)
|
24
|
-
uri.path.chomp("/")
|
24
|
+
path_prefix = uri.path.chomp("/")
|
25
|
+
if path_prefix.empty?
|
26
|
+
path
|
27
|
+
else
|
28
|
+
path.sub(/\A\/d/) {path_prefix}
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -17,6 +17,7 @@
|
|
17
17
|
# License along with this library; if not, write to the Free Software
|
18
18
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
19
|
|
20
|
+
require "csv"
|
20
21
|
require "rexml/document"
|
21
22
|
require "json"
|
22
23
|
|
@@ -78,6 +79,9 @@ module Groonga
|
|
78
79
|
when :xml
|
79
80
|
header, body = parse_xml(raw_response)
|
80
81
|
return_code = header[0] if header
|
82
|
+
when :tsv
|
83
|
+
header, body = parse_tsv(raw_response)
|
84
|
+
return_code = header["return_code"] if header
|
81
85
|
else
|
82
86
|
header = nil
|
83
87
|
body = raw_response
|
@@ -129,6 +133,46 @@ module Groonga
|
|
129
133
|
end
|
130
134
|
end
|
131
135
|
end
|
136
|
+
|
137
|
+
def parse_tsv(response)
|
138
|
+
tsv = CSV.new(response, col_sep: "\t")
|
139
|
+
raw_header = tsv.shift
|
140
|
+
return nil, nil if raw_header.nil?
|
141
|
+
|
142
|
+
header = parse_tsv_header(raw_header)
|
143
|
+
return header, nil unless header["return_code"].zero?
|
144
|
+
|
145
|
+
body = parse_tsv_body(tsv)
|
146
|
+
[header, body]
|
147
|
+
end
|
148
|
+
|
149
|
+
def parse_tsv_header(raw_header)
|
150
|
+
header = {
|
151
|
+
"return_code" => Integer(raw_header[0], 10),
|
152
|
+
"start_time" => Float(raw_header[1]),
|
153
|
+
"elapsed_time" => Float(raw_header[2]),
|
154
|
+
}
|
155
|
+
if raw_header.size >= 4
|
156
|
+
header["error"] = {
|
157
|
+
"message" => raw_header[3],
|
158
|
+
}
|
159
|
+
if raw_header.size >= 5
|
160
|
+
header["error"]["function"] = raw_header[4]
|
161
|
+
header["error"]["file"] = raw_header[5]
|
162
|
+
header["error"]["line"] = Integer(raw_header[6])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
header
|
166
|
+
end
|
167
|
+
|
168
|
+
def parse_tsv_body(tsv)
|
169
|
+
body = []
|
170
|
+
tsv.each do |row|
|
171
|
+
break if row.size == 1 and row[0] == "END"
|
172
|
+
body << row
|
173
|
+
end
|
174
|
+
body
|
175
|
+
end
|
132
176
|
end
|
133
177
|
|
134
178
|
# @return [Groonga::Command] The command for the request.
|
@@ -20,10 +20,50 @@ module Groonga
|
|
20
20
|
class Client
|
21
21
|
module Response
|
22
22
|
class Error < Base
|
23
|
-
# @return [String] The error message of the error response.
|
23
|
+
# @return [String, nil] The error message of the error response.
|
24
|
+
#
|
24
25
|
# @since 0.1.0
|
25
26
|
def message
|
26
|
-
|
27
|
+
error_message
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String, nil] The function name where the error is occurred.
|
31
|
+
#
|
32
|
+
# @since 0.5.9
|
33
|
+
def function
|
34
|
+
if header.nil?
|
35
|
+
nil
|
36
|
+
elsif header_v1?
|
37
|
+
header[4]
|
38
|
+
else
|
39
|
+
(header["error"] || {})["function"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String, nil] The file name where the error is occurred.
|
44
|
+
#
|
45
|
+
# @since 0.5.9
|
46
|
+
def file
|
47
|
+
if header.nil?
|
48
|
+
nil
|
49
|
+
elsif header_v1?
|
50
|
+
header[5]
|
51
|
+
else
|
52
|
+
(header["error"] || {})["file"]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [String, nil] The line where the error is occurred.
|
57
|
+
#
|
58
|
+
# @since 0.5.9
|
59
|
+
def line
|
60
|
+
if header.nil?
|
61
|
+
nil
|
62
|
+
elsif header_v1?
|
63
|
+
header[5]
|
64
|
+
else
|
65
|
+
(header["error"] || {})["line"]
|
66
|
+
end
|
27
67
|
end
|
28
68
|
end
|
29
69
|
end
|
@@ -100,6 +100,78 @@ module Groonga
|
|
100
100
|
|
101
101
|
drilldowns
|
102
102
|
end
|
103
|
+
|
104
|
+
def parse_tsv_body(tsv)
|
105
|
+
record_sets = []
|
106
|
+
|
107
|
+
n_hits = parse_tsv_n_hits(tsv.shift)
|
108
|
+
columns = parse_tsv_columns(tsv.shift)
|
109
|
+
records = []
|
110
|
+
loop do
|
111
|
+
row = tsv.shift
|
112
|
+
break if row.size == 1 and row[0] == "END"
|
113
|
+
if (row.size % 4).zero? and row[0] == "[" and row[-1] == "]"
|
114
|
+
next_n_hits_row = records.pop
|
115
|
+
record_sets << [
|
116
|
+
[n_hits],
|
117
|
+
columns,
|
118
|
+
*records,
|
119
|
+
]
|
120
|
+
n_hits = parse_tsv_n_hits(next_n_hits_row)
|
121
|
+
columns = parse_tsv_columns(row)
|
122
|
+
records = []
|
123
|
+
next
|
124
|
+
end
|
125
|
+
records << parse_tsv_record(row)
|
126
|
+
end
|
127
|
+
|
128
|
+
record_sets << [
|
129
|
+
[n_hits],
|
130
|
+
columns,
|
131
|
+
*records,
|
132
|
+
]
|
133
|
+
record_sets
|
134
|
+
end
|
135
|
+
|
136
|
+
def parse_tsv_n_hits(row)
|
137
|
+
Integer(row[0], 10)
|
138
|
+
end
|
139
|
+
|
140
|
+
def parse_tsv_columns(row)
|
141
|
+
columns = []
|
142
|
+
column = nil
|
143
|
+
row.each do |value|
|
144
|
+
case value
|
145
|
+
when "["
|
146
|
+
column = []
|
147
|
+
when "]"
|
148
|
+
columns << column
|
149
|
+
else
|
150
|
+
column << value
|
151
|
+
end
|
152
|
+
end
|
153
|
+
columns
|
154
|
+
end
|
155
|
+
|
156
|
+
def parse_tsv_record(row)
|
157
|
+
record = []
|
158
|
+
column_value = nil
|
159
|
+
row.each do |value|
|
160
|
+
case value
|
161
|
+
when "["
|
162
|
+
column_value = []
|
163
|
+
when "]"
|
164
|
+
record << column_value
|
165
|
+
else
|
166
|
+
if column_value
|
167
|
+
column_value << value
|
168
|
+
else
|
169
|
+
record << value
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
record
|
174
|
+
end
|
103
175
|
end
|
104
176
|
|
105
177
|
include Enumerable
|
data/test/response/helper.rb
CHANGED
@@ -30,4 +30,9 @@ module TestResponseHelper
|
|
30
30
|
parse_raw_response_raw(command_name, {"output_type" => "xml"},
|
31
31
|
raw_response)
|
32
32
|
end
|
33
|
+
|
34
|
+
def parse_raw_tsv_response(command_name, raw_response)
|
35
|
+
parse_raw_response_raw(command_name, {"output_type" => "tsv"},
|
36
|
+
raw_response)
|
37
|
+
end
|
33
38
|
end
|
data/test/response/test-error.rb
CHANGED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Copyright (C) 2018 Kouhei Sutou <kou@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
|
+
require "response/helper"
|
18
|
+
|
19
|
+
class TestResponseSelectTSV < Test::Unit::TestCase
|
20
|
+
include TestResponseHelper
|
21
|
+
|
22
|
+
def drilldown(key, n_hits, records)
|
23
|
+
Groonga::Client::Response::Select::Drilldown.new(key, n_hits, records)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_error
|
27
|
+
raw_response = <<-TSV
|
28
|
+
-22 0 0.0 "message" "function" "file" 29
|
29
|
+
|
30
|
+
END
|
31
|
+
TSV
|
32
|
+
|
33
|
+
response = parse_raw_tsv_response("select", raw_response)
|
34
|
+
assert_equal({
|
35
|
+
:return_code => -22,
|
36
|
+
:start_time => Time.at(0),
|
37
|
+
:elapsed_time => 0.0,
|
38
|
+
:error => {
|
39
|
+
:message => "message",
|
40
|
+
:function => "function",
|
41
|
+
:file => "file",
|
42
|
+
:line => 29,
|
43
|
+
},
|
44
|
+
},
|
45
|
+
{
|
46
|
+
:return_code => response.return_code,
|
47
|
+
:start_time => response.start_time,
|
48
|
+
:elapsed_time => response.elapsed_time,
|
49
|
+
:error => {
|
50
|
+
:message => response.message,
|
51
|
+
:function => response.function,
|
52
|
+
:file => response.file,
|
53
|
+
:line => response.line,
|
54
|
+
},
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_basic
|
59
|
+
raw_response = <<-TSV
|
60
|
+
0 0 0.0
|
61
|
+
100
|
62
|
+
[ "_id" "UInt32" ]
|
63
|
+
1
|
64
|
+
2
|
65
|
+
END
|
66
|
+
TSV
|
67
|
+
|
68
|
+
response = parse_raw_tsv_response("select", raw_response)
|
69
|
+
assert_equal({
|
70
|
+
:return_code => 0,
|
71
|
+
:start_time => Time.at(0),
|
72
|
+
:elapsed_time => 0.0,
|
73
|
+
:records => [
|
74
|
+
{"_id" => "1"},
|
75
|
+
{"_id" => "2"},
|
76
|
+
],
|
77
|
+
},
|
78
|
+
{
|
79
|
+
:return_code => response.return_code,
|
80
|
+
:start_time => response.start_time,
|
81
|
+
:elapsed_time => response.elapsed_time,
|
82
|
+
:records => response.records,
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_drilldown
|
87
|
+
raw_response = <<-TSV
|
88
|
+
0 0 0.0
|
89
|
+
100
|
90
|
+
[ "_id" "UInt32" ]
|
91
|
+
7
|
92
|
+
[ "_key" "ShortText" ] [ "_nsubrecs" "UInt32" ]
|
93
|
+
"2.2.0" "18044"
|
94
|
+
"2.3.0" "18115"
|
95
|
+
"2.4.0" "14594"
|
96
|
+
END
|
97
|
+
TSV
|
98
|
+
|
99
|
+
response = parse_raw_response_raw("select",
|
100
|
+
{
|
101
|
+
"drilldown" => "version",
|
102
|
+
"output_type" => "tsv",
|
103
|
+
},
|
104
|
+
raw_response)
|
105
|
+
drilldown_records = [
|
106
|
+
{"_key" => "2.2.0", "_nsubrecs" => "18044"},
|
107
|
+
{"_key" => "2.3.0", "_nsubrecs" => "18115"},
|
108
|
+
{"_key" => "2.4.0", "_nsubrecs" => "14594"},
|
109
|
+
]
|
110
|
+
assert_equal({
|
111
|
+
:return_code => 0,
|
112
|
+
:start_time => Time.at(0),
|
113
|
+
:elapsed_time => 0.0,
|
114
|
+
:records => [],
|
115
|
+
:drilldowns => [
|
116
|
+
drilldown("version", 7, drilldown_records),
|
117
|
+
],
|
118
|
+
},
|
119
|
+
{
|
120
|
+
:return_code => response.return_code,
|
121
|
+
:start_time => response.start_time,
|
122
|
+
:elapsed_time => response.elapsed_time,
|
123
|
+
:records => response.records,
|
124
|
+
:drilldowns => response.drilldowns,
|
125
|
+
})
|
126
|
+
end
|
127
|
+
end
|
data/test/test-client.rb
CHANGED
@@ -491,7 +491,7 @@ EOH
|
|
491
491
|
|
492
492
|
def test_with_trailing_slash
|
493
493
|
stub_response("[]")
|
494
|
-
options = component_based_open_options.merge(:path => "/sub_path/")
|
494
|
+
options = component_based_open_options.merge(:path => "/sub_path/d/")
|
495
495
|
Groonga::Client.open(options) do |client|
|
496
496
|
client.status
|
497
497
|
end
|
@@ -500,7 +500,7 @@ EOH
|
|
500
500
|
|
501
501
|
def test_without_trailing_slash
|
502
502
|
stub_response("[]")
|
503
|
-
options = component_based_open_options.merge(:path => "/sub_path")
|
503
|
+
options = component_based_open_options.merge(:path => "/sub_path/d")
|
504
504
|
Groonga::Client.open(options) do |client|
|
505
505
|
client.status
|
506
506
|
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.5.
|
4
|
+
version: 0.5.9
|
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:
|
13
|
+
date: 2018-07-13 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
|
165
164
|
- groonga-client-index-check
|
166
165
|
- groonga-client-index-recreate
|
166
|
+
- groonga-client
|
167
167
|
extensions: []
|
168
168
|
extra_rdoc_files: []
|
169
169
|
files:
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/groonga/client/empty-request.rb
|
189
189
|
- lib/groonga/client/error.rb
|
190
190
|
- lib/groonga/client/protocol/error.rb
|
191
|
+
- lib/groonga/client/protocol/file.rb
|
191
192
|
- lib/groonga/client/protocol/gqtp.rb
|
192
193
|
- lib/groonga/client/protocol/http.rb
|
193
194
|
- lib/groonga/client/protocol/http/coolio.rb
|
@@ -251,6 +252,7 @@ files:
|
|
251
252
|
- test/response/test-schema.rb
|
252
253
|
- test/response/test-select-command-version1.rb
|
253
254
|
- test/response/test-select-command-version3.rb
|
255
|
+
- test/response/test-select-tsv.rb
|
254
256
|
- test/response/test-select-xml.rb
|
255
257
|
- test/response/test-status.rb
|
256
258
|
- test/response/test-table-create.rb
|
@@ -281,41 +283,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
283
|
version: '0'
|
282
284
|
requirements: []
|
283
285
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.
|
286
|
+
rubygems_version: 2.7.6
|
285
287
|
signing_key:
|
286
288
|
specification_version: 4
|
287
289
|
summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
|
288
290
|
with pure Ruby. You can use it without Groonga.
|
289
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
|
290
296
|
- test/test-script-syntax.rb
|
291
|
-
- test/
|
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
|
292
307
|
- test/protocol/test-gqtp.rb
|
293
|
-
- test/
|
308
|
+
- test/protocol/test-http.rb
|
309
|
+
- test/run-test.rb
|
310
|
+
- test/response/test-base.rb
|
311
|
+
- test/response/test-select-tsv.rb
|
312
|
+
- test/response/test-load.rb
|
313
|
+
- test/response/test-column-list.rb
|
314
|
+
- test/response/helper.rb
|
294
315
|
- test/response/test-error.rb
|
295
|
-
- test/response/test-table-
|
316
|
+
- test/response/test-table-list.rb
|
317
|
+
- test/response/test-status.rb
|
296
318
|
- test/response/test-select-xml.rb
|
319
|
+
- test/response/test-schema.rb
|
297
320
|
- test/response/test-select-command-version3.rb
|
298
|
-
- test/response/test-table-list.rb
|
299
|
-
- test/response/test-column-list.rb
|
300
|
-
- test/response/test-load.rb
|
301
|
-
- test/response/helper.rb
|
302
|
-
- test/response/test-base.rb
|
303
321
|
- test/response/test-select-command-version1.rb
|
304
|
-
- test/response/test-status.rb
|
305
322
|
- test/response/test-table-create.rb
|
323
|
+
- test/response/test-table-remove.rb
|
306
324
|
- test/results/test-table-list.rb
|
307
|
-
- test/test-command.rb
|
308
|
-
- test/run-test.rb
|
309
|
-
- test/request/test-generic.rb
|
310
|
-
- test/request/select/test-values-parameter.rb
|
311
|
-
- test/request/select/test-output-columns-parameter.rb
|
312
|
-
- test/request/select/test-scorer.rb
|
313
|
-
- test/request/select/test-backward-compatible-sort-keys-parameter.rb
|
314
|
-
- test/request/select/test-filter.rb
|
315
|
-
- test/request/select/test-sort-keys-parameter.rb
|
316
|
-
- test/request/test-select.rb
|
317
|
-
- test/request/test-merger.rb
|
318
|
-
- test/test-client.rb
|
319
|
-
- test/command-line/test-index-recreate.rb
|
320
|
-
- test/command-line/helper.rb
|
321
|
-
- test/command-line/test-index-check.rb
|