groonga-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/groonga-client +3 -94
- data/doc/text/news.md +8 -1
- data/lib/groonga/client.rb +3 -1
- data/lib/groonga/client/command-line/groonga-client.rb +198 -0
- data/lib/groonga/client/default.rb +25 -0
- data/lib/groonga/client/protocol/http/synchronous.rb +10 -0
- data/lib/groonga/client/version.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290f3a653fc46b26b559ce12fbf1563f776c8289
|
4
|
+
data.tar.gz: 1d95b138d76c57a81a487e057ac7175463a0aa87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937618894500db79f02bc86bc19468ffe209c8334cdb401da05112f8de5db9bf61ad5163b0f2372815e0070823aa97ccdbf53ebb5e63efd72e2f7ab17a819945
|
7
|
+
data.tar.gz: a8124dd6957a86bbab1173c7095e15d8a830b6d521edd6b5ce9d8a69bc24d2b95ed7d411c35261851ae55d19e00f8ca764dbecb2ce81cdf9d2dd82432143ca66
|
data/bin/groonga-client
CHANGED
@@ -17,98 +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 "
|
21
|
-
require "optparse"
|
22
|
-
require "json"
|
20
|
+
require "groonga/client/command-line/groonga-client"
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
require "groonga/client"
|
27
|
-
|
28
|
-
def default_port(protocol)
|
29
|
-
case protocol
|
30
|
-
when :http
|
31
|
-
10041
|
32
|
-
when :gqtp
|
33
|
-
10043
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def run_command(client, command)
|
38
|
-
response = client.execute(command)
|
39
|
-
case command.output_type
|
40
|
-
when :json
|
41
|
-
puts(JSON.pretty_generate([response.header, response.body]))
|
42
|
-
when :xml
|
43
|
-
puts(response.raw)
|
44
|
-
else
|
45
|
-
puts(response.body)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
options = OpenStruct.new
|
50
|
-
options.protocol = :http
|
51
|
-
options.host = "localhost"
|
52
|
-
options.port = nil
|
53
|
-
|
54
|
-
parser = OptionParser.new
|
55
|
-
parser.version = Groonga::Client::VERSION
|
56
|
-
parser.banner += " GROONGA_COMMAND_FILE1 GROONGA_COMMAND_FILE2 ..."
|
57
|
-
parser.separator("")
|
58
|
-
parser.separator("Connection:")
|
59
|
-
available_protocols = [:http, :gqtp]
|
60
|
-
parser.on("--protocol=PROTOCOL", [:http, :gqtp],
|
61
|
-
"Protocol to connect to Groonga server.",
|
62
|
-
"[#{available_protocols.join(", ")}]",
|
63
|
-
"(#{options.protocol})") do |protocol|
|
64
|
-
options.protocol = protocol
|
65
|
-
end
|
66
|
-
parser.on("--host=HOST",
|
67
|
-
"Groonga server to be connected.",
|
68
|
-
"(#{options.host})") do |host|
|
69
|
-
options.host = host
|
70
|
-
end
|
71
|
-
parser.on("--port=PORT", Integer,
|
72
|
-
"Port number of Groonga server to be connected.",
|
73
|
-
"(auto)") do |port|
|
74
|
-
options.port = port
|
75
|
-
end
|
76
|
-
command_file_paths = parser.parse!(ARGV)
|
77
|
-
|
78
|
-
options.port ||= default_port(options.protocol)
|
79
|
-
|
80
|
-
client = Groonga::Client.new(:protocol => options.protocol,
|
81
|
-
:host => options.host,
|
82
|
-
:port => options.port,
|
83
|
-
:backend => :synchronous)
|
84
|
-
parser = Groonga::Command::Parser.new
|
85
|
-
parser.on_command do |command|
|
86
|
-
run_command(client, command)
|
87
|
-
end
|
88
|
-
|
89
|
-
parser.on_load_columns do |command, columns|
|
90
|
-
command[:columns] ||= columns.join(",")
|
91
|
-
end
|
92
|
-
values = []
|
93
|
-
parser.on_load_value do |_, value|
|
94
|
-
values << value
|
95
|
-
end
|
96
|
-
parser.on_load_complete do |command|
|
97
|
-
command[:values] ||= Yajl::Encoder.encode(values)
|
98
|
-
run_command(client, command)
|
99
|
-
values.clear
|
100
|
-
end
|
101
|
-
|
102
|
-
if command_file_paths.empty?
|
103
|
-
$stdin.each_line do |line|
|
104
|
-
parser << line
|
105
|
-
end
|
106
|
-
else
|
107
|
-
command_file_paths.each do |command_file_path|
|
108
|
-
File.open(command_file_path) do |command_file|
|
109
|
-
command_file.each_line do |line|
|
110
|
-
parser << line
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
22
|
+
client = Groonga::Client::CommandLine::GroongaClient.new
|
23
|
+
exit(client.run(ARGV))
|
data/doc/text/news.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.1.2 - 2015-05-13
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* groonga-client: Supported split load.
|
8
|
+
* groonga-client: Added `--read-timeout` option.
|
9
|
+
|
3
10
|
## 0.1.1 - 2015-04-20
|
4
11
|
|
5
12
|
### Improvements
|
6
13
|
|
7
|
-
* groonga-client:
|
14
|
+
* groonga-client: Added a command that sends Groonga commands to a
|
8
15
|
Groonga server.
|
9
16
|
|
10
17
|
## 0.1.0 - 2014-11-05
|
data/lib/groonga/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
3
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2013-
|
4
|
+
# Copyright (C) 2013-2015 Kouhei Sutou <kou@clear-code.com>
|
5
5
|
#
|
6
6
|
# This library is free software; you can redistribute it and/or
|
7
7
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -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 "groonga/client/default"
|
20
21
|
require "groonga/client/command"
|
21
22
|
require "groonga/client/empty-request"
|
22
23
|
require "groonga/client/protocol/gqtp"
|
@@ -64,6 +65,7 @@ module Groonga
|
|
64
65
|
def initialize(options={})
|
65
66
|
options = options.dup
|
66
67
|
protocol = options.delete(:protocol) || :gqtp
|
68
|
+
options[:read_timeout] ||= Default::READ_TIMEOUT
|
67
69
|
|
68
70
|
@connection = nil
|
69
71
|
if protocol == :gqtp
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# Copyright (C) 2015 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 "ostruct"
|
18
|
+
require "optparse"
|
19
|
+
require "json"
|
20
|
+
|
21
|
+
require "groonga/command/parser"
|
22
|
+
|
23
|
+
require "groonga/client"
|
24
|
+
|
25
|
+
module Groonga
|
26
|
+
class Client
|
27
|
+
module CommandLine
|
28
|
+
class GroongaClient
|
29
|
+
def initialize
|
30
|
+
@protocol = :http
|
31
|
+
@host = "localhost"
|
32
|
+
@port = nil
|
33
|
+
|
34
|
+
@read_timeout = Default::READ_TIMEOUT
|
35
|
+
|
36
|
+
@runner_options = {
|
37
|
+
:split_load_chunk_size => 10000,
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def run(argv)
|
42
|
+
command_file_paths = parse_command_line(argv)
|
43
|
+
|
44
|
+
@client = Groonga::Client.new(:protocol => @protocol,
|
45
|
+
:host => @host,
|
46
|
+
:port => @port,
|
47
|
+
:read_timeout => @read_timeout,
|
48
|
+
:backend => :synchronous)
|
49
|
+
runner = Runner.new(@client, @runner_options)
|
50
|
+
|
51
|
+
if command_file_paths.empty?
|
52
|
+
$stdin.each_line do |line|
|
53
|
+
runner << line
|
54
|
+
end
|
55
|
+
else
|
56
|
+
command_file_paths.each do |command_file_path|
|
57
|
+
File.open(command_file_path) do |command_file|
|
58
|
+
command_file.each_line do |line|
|
59
|
+
runner << line
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def parse_command_line(argv)
|
70
|
+
parser = OptionParser.new
|
71
|
+
parser.version = VERSION
|
72
|
+
parser.banner += " GROONGA_COMMAND_FILE1 GROONGA_COMMAND_FILE2 ..."
|
73
|
+
|
74
|
+
parser.separator("")
|
75
|
+
|
76
|
+
parser.separator("Connection:")
|
77
|
+
|
78
|
+
available_protocols = [:http, :gqtp]
|
79
|
+
parser.on("--protocol=PROTOCOL", [:http, :gqtp],
|
80
|
+
"Protocol to connect to Groonga server.",
|
81
|
+
"[#{available_protocols.join(", ")}]",
|
82
|
+
"(#{@protocol})") do |protocol|
|
83
|
+
@protocol = protocol
|
84
|
+
end
|
85
|
+
|
86
|
+
parser.on("--host=HOST",
|
87
|
+
"Groonga server to be connected.",
|
88
|
+
"(#{@host})") do |host|
|
89
|
+
@host = host
|
90
|
+
end
|
91
|
+
|
92
|
+
parser.on("--port=PORT", Integer,
|
93
|
+
"Port number of Groonga server to be connected.",
|
94
|
+
"(auto)") do |port|
|
95
|
+
@port = port
|
96
|
+
end
|
97
|
+
|
98
|
+
parser.on("--read-timeout=TIMEOUT", Integer,
|
99
|
+
"Timeout on reading response from Groonga server.",
|
100
|
+
"You can disable timeout by specifying -1.",
|
101
|
+
"(#{@read_timeout})") do |timeout|
|
102
|
+
@read_timeout = timeout
|
103
|
+
end
|
104
|
+
|
105
|
+
parser.on("--split-load-chunk-size=SIZE", Integer,
|
106
|
+
"Split a large load to small loads.",
|
107
|
+
"Each small load has at most SIZE records.",
|
108
|
+
"Set 0 to SIZE to disable this feature.",
|
109
|
+
"(#{@runner_options[:split_load_chunk_size]})") do |size|
|
110
|
+
@runner_options[:split_load_chunk_size] = size
|
111
|
+
end
|
112
|
+
|
113
|
+
command_file_paths = parser.parse(argv)
|
114
|
+
|
115
|
+
@port ||= default_port(@protocol)
|
116
|
+
|
117
|
+
command_file_paths
|
118
|
+
end
|
119
|
+
|
120
|
+
def default_port(protocol)
|
121
|
+
case protocol
|
122
|
+
when :http
|
123
|
+
10041
|
124
|
+
when :gqtp
|
125
|
+
10043
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Runner
|
130
|
+
def initialize(client, options={})
|
131
|
+
@client = client
|
132
|
+
@split_load_chunk_size = options[:split_load_chunk_size] || 10000
|
133
|
+
@load_values = []
|
134
|
+
@parser = create_command_parser
|
135
|
+
end
|
136
|
+
|
137
|
+
def <<(line)
|
138
|
+
@parser << line
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
def create_command_parser
|
143
|
+
parser = Groonga::Command::Parser.new
|
144
|
+
|
145
|
+
parser.on_command do |command|
|
146
|
+
run_command(command)
|
147
|
+
end
|
148
|
+
|
149
|
+
parser.on_load_columns do |command, columns|
|
150
|
+
command[:columns] ||= columns.join(",")
|
151
|
+
end
|
152
|
+
|
153
|
+
parser.on_load_value do |command, value|
|
154
|
+
unless command[:values]
|
155
|
+
@load_values << value
|
156
|
+
if @load_values.size == @split_load_chunk_size
|
157
|
+
consume_load_values(command)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
command.original_source.clear
|
161
|
+
end
|
162
|
+
|
163
|
+
parser.on_load_complete do |command|
|
164
|
+
if command[:values]
|
165
|
+
run_command(client, command)
|
166
|
+
else
|
167
|
+
consume_load_values(command)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
parser
|
172
|
+
end
|
173
|
+
|
174
|
+
def consume_load_values(load_command)
|
175
|
+
return if @load_values.empty?
|
176
|
+
|
177
|
+
load_command[:values] = Yajl::Encoder.encode(@load_values)
|
178
|
+
run_command(load_command)
|
179
|
+
@load_values.clear
|
180
|
+
load_command[:values] = nil
|
181
|
+
end
|
182
|
+
|
183
|
+
def run_command(command)
|
184
|
+
response = @client.execute(command)
|
185
|
+
case command.output_type
|
186
|
+
when :json
|
187
|
+
puts(JSON.pretty_generate([response.header, response.body]))
|
188
|
+
when :xml
|
189
|
+
puts(response.raw)
|
190
|
+
else
|
191
|
+
puts(response.body)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright (C) 2015 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
|
+
module Groonga
|
18
|
+
class Client
|
19
|
+
module Default
|
20
|
+
# The default timeout on reading response from Groonga server in
|
21
|
+
# seconds.
|
22
|
+
READ_TIMEOUT = 60
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -35,6 +35,7 @@ module Groonga
|
|
35
35
|
def send(command)
|
36
36
|
begin
|
37
37
|
Net::HTTP.start(@host, @port) do |http|
|
38
|
+
http.read_timeout = read_timeout
|
38
39
|
response = send_request(http, command)
|
39
40
|
case response
|
40
41
|
when Net::HTTPSuccess, Net::HTTPBadRequest
|
@@ -89,6 +90,15 @@ module Groonga
|
|
89
90
|
end
|
90
91
|
|
91
92
|
private
|
93
|
+
def read_timeout
|
94
|
+
timeout = @options[:read_timeout]
|
95
|
+
if timeout < 0
|
96
|
+
nil
|
97
|
+
else
|
98
|
+
timeout
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
92
102
|
def send_request(http, command)
|
93
103
|
if command.name == "load"
|
94
104
|
raw_values = command[:values]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013-
|
3
|
+
# Copyright (C) 2013-2015 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -18,6 +18,6 @@
|
|
18
18
|
|
19
19
|
module Groonga
|
20
20
|
class Client
|
21
|
-
VERSION = "0.1.
|
21
|
+
VERSION = "0.1.2"
|
22
22
|
end
|
23
23
|
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.1.
|
4
|
+
version: 0.1.2
|
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: 2015-
|
13
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -174,7 +174,9 @@ files:
|
|
174
174
|
- doc/text/news.md
|
175
175
|
- groonga-client.gemspec
|
176
176
|
- lib/groonga/client.rb
|
177
|
+
- lib/groonga/client/command-line/groonga-client.rb
|
177
178
|
- lib/groonga/client/command.rb
|
179
|
+
- lib/groonga/client/default.rb
|
178
180
|
- lib/groonga/client/empty-request.rb
|
179
181
|
- lib/groonga/client/error.rb
|
180
182
|
- lib/groonga/client/protocol/error.rb
|