groonga-client 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d5741b1b6164b64e7182714c95af93da3b9ff9c
4
- data.tar.gz: 3fbba89037ca39c830e91e9c0b3a067a1001ea5a
3
+ metadata.gz: 37800c0ceaac12320a9c1d92cf63012703cf8b1d
4
+ data.tar.gz: d7dfd6abd5db78f48e8602759245d110e593c632
5
5
  SHA512:
6
- metadata.gz: 4db4ee9f1ee50a06dee0f93e48783dd9d831e11de89be558f071475adcb02dafbc4a770f6b136585bde797655446cbf2f831bbabdb27d13f4fbea736a63a3215
7
- data.tar.gz: 6e0bd4b40e1967f45f0f3070f006a23178fa81aee66fe8b18227f41d2936a2a71eacffecebd23a2a6cecf2653c1f5694e05bd43b282d981bffa3e9450aaf72b3
6
+ metadata.gz: 48a5b7f236ada9ad6aa43d29901ac253721cb101ecb37141320fc3cddb29b0f6d45bf5b4ba37b85ae6b3630ea4f70305acce34d4425def8ec72badc1d7f47a3c
7
+ data.tar.gz: ff37c41507bcdf210f557eb6afa4b54443cd14b5ee9246bfc197b8c30691875ce1b78e66c601578e6726a37f63997d4f60d19e6685b6aa5ed9398758538efb2e
data/doc/text/news.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.2.6 - 2016-06-17
4
+
5
+ ### Improvements
6
+
7
+ * Supported command version 3.
8
+
9
+ * Added {Groonga::Client::Response#return_code}.
10
+ {Groonga::Client::Response#status_code} is deprecated. Use
11
+ `#return_code` instead.
12
+
13
+ * `select` response: Supported vector of `Time`.
14
+
3
15
  ## 0.2.5 - 2016-04-02
4
16
 
5
17
  ### Fixes
@@ -51,7 +51,6 @@ Gem::Specification.new do |spec|
51
51
  spec.add_development_dependency("bundler")
52
52
  spec.add_development_dependency("rake")
53
53
  spec.add_development_dependency("test-unit")
54
- spec.add_development_dependency("test-unit-notify")
55
54
  spec.add_development_dependency("test-unit-rr")
56
55
  spec.add_development_dependency("packnga")
57
56
  spec.add_development_dependency("redcarpet")
@@ -39,7 +39,7 @@ module Groonga
39
39
  # response object.
40
40
  #
41
41
  # @param [Groonga::Command::Base] The command of the request.
42
- # @param [String] The raw (not parsed) response returned by groonga
42
+ # @param [String] The raw (not parsed) response returned by Groonga
43
43
  # server.
44
44
  # @return [Base]
45
45
  def parse(command, raw_response)
@@ -61,16 +61,26 @@ module Groonga
61
61
  class Base
62
62
  class << self
63
63
  def parse(command, raw_response)
64
+ return_code = nil
64
65
  case command.output_type
65
66
  when :json
66
- header, body = JSON.parse(raw_response)
67
+ response = JSON.parse(raw_response)
68
+ if response.is_a?(::Array)
69
+ header, body = response
70
+ return_code = header[0] if header
71
+ else
72
+ header = response["header"]
73
+ body = response["body"]
74
+ return_code = header["return_code"] if header
75
+ end
67
76
  when :xml
68
77
  header, body = parse_xml(raw_response)
78
+ return_code = header[0] if header
69
79
  else
70
80
  header = nil
71
81
  body = raw_response
72
82
  end
73
- if header.nil? or header[0].zero?
83
+ if header.nil? or return_code == 0
74
84
  response = new(command, header, body)
75
85
  else
76
86
  response = Error.new(command, header, body)
@@ -136,7 +146,7 @@ module Groonga
136
146
  # `[return_code, start_time, elapsed_time_in_seconds, error_message, error_location]`
137
147
  # for error case.
138
148
  # @see http://groonga.org/docs/reference/command/output_format.html#header
139
- # Defails for header format.
149
+ # Details for header format.
140
150
  attr_accessor :header
141
151
  # @return [::Hash] The body of response. Its content is depends on
142
152
  # command.
@@ -144,7 +154,7 @@ module Groonga
144
154
  # The list of built-in commands.
145
155
  attr_accessor :body
146
156
  # @return [String] The unparsed response. It may be JSON, XML or
147
- # groonga command format.
157
+ # Groonga command format.
148
158
  attr_accessor :raw
149
159
 
150
160
  def initialize(command, header, body)
@@ -154,35 +164,72 @@ module Groonga
154
164
  self.raw = nil
155
165
  end
156
166
 
167
+ # @return [Integer] The return code of the response.
168
+ # @since 0.2.6
169
+ def return_code
170
+ if header.nil?
171
+ 0
172
+ elsif header_v1?
173
+ header[0]
174
+ else
175
+ header["return_code"] || 0
176
+ end
177
+ end
178
+
157
179
  # @return [Integer] The status code of the response.
158
180
  # @since 0.1.0
181
+ #
182
+ # @deprecated since 0.2.6. Use {return_code} instead.
159
183
  def status_code
160
- (header || [0])[0]
184
+ return_code
161
185
  end
162
186
 
163
187
  # @return [Time] The time of the request is accepted.
164
188
  # @since 0.1.0
165
189
  def start_time
166
- Time.at((header || [0, 0])[1])
190
+ if header.nil?
191
+ Time.at(0)
192
+ elsif header_v1?
193
+ Time.at(header[1])
194
+ else
195
+ Time.at(header["start_time"])
196
+ end
167
197
  end
168
198
 
169
- # @return [Time] The elapsed time of the request.
199
+ # @return [Float] The elapsed time of the request.
170
200
  # @since 0.1.0
171
201
  def elapsed_time
172
- (header || [0, 0, 0.0])[2]
202
+ if header.nil?
203
+ 0.0
204
+ elsif header_v1?
205
+ header[2]
206
+ else
207
+ header["elapsed_time"]
208
+ end
173
209
  end
174
210
 
175
211
  # @return [String, nil] The error message of the response.
176
212
  # @since 0.2.4
177
213
  def error_message
178
- (header || [0, 0, 0.0, nil])[3]
214
+ if header.nil?
215
+ nil
216
+ elsif header_v1?
217
+ header[3]
218
+ else
219
+ (header["error"] || {})["message"]
220
+ end
179
221
  end
180
222
 
181
223
  # @return [Boolean] `true` if the request is processed successfully,
182
224
  # `false` otherwise.
183
225
  # @since 0.1.0
184
226
  def success?
185
- status_code.zero?
227
+ return_code.zero?
228
+ end
229
+
230
+ private
231
+ def header_v1?
232
+ header.is_a?(::Array)
186
233
  end
187
234
  end
188
235
  end
@@ -36,57 +36,92 @@ module Groonga
36
36
 
37
37
  private
38
38
  def parse_body(body)
39
- @n_hits, @records = parse_match_records(body.first)
40
- @drilldowns = parse_drilldowns(body[1..-1])
39
+ if body.is_a?(::Array)
40
+ @n_hits, @records = parse_match_records_v1(body.first)
41
+ @drilldowns = parse_drilldowns_v1(body[1..-1])
42
+ else
43
+ @n_hits, @records = parse_match_records_v3(body)
44
+ @drilldowns = parse_drilldowns_v3(body["drilldowns"])
45
+ end
41
46
  body
42
47
  end
43
48
 
44
- def parse_result(raw_result)
45
- n_hits = raw_result.first.first
49
+ def parse_records(raw_columns, raw_records)
46
50
  column_names = {}
47
- properties = raw_result[1].collect do |column_name, column_type|
48
- base_column_name = column_name
51
+ columns = raw_columns.collect do |column|
52
+ if column.is_a?(::Array)
53
+ name, type = column
54
+ else
55
+ name = column["name"]
56
+ type = column["type"]
57
+ end
58
+ base_column_name = name
49
59
  suffix = 2
50
- while column_names.key?(column_name)
51
- column_name = "#{base_column_name}#{suffix}"
60
+ while column_names.key?(name)
61
+ name = "#{base_column_name}#{suffix}"
52
62
  suffix += 1
53
63
  end
54
- column_names[column_name] = true
55
- [column_name, column_type]
64
+ column_names[name] = true
65
+ [name, type]
56
66
  end
57
- infos = raw_result[2..-1] || []
58
- items = infos.collect do |info|
59
- item = {}
60
- properties.each_with_index do |(name, type), i|
61
- item[name] = convert_value(info[i], type)
67
+
68
+ (raw_records || []).collect do |raw_record|
69
+ record = {}
70
+ columns.each_with_index do |(name, type), i|
71
+ record[name] = convert_value(raw_record[i], type)
62
72
  end
63
- item
73
+ record
64
74
  end
65
- [n_hits, items]
66
75
  end
67
76
 
68
77
  def convert_value(value, type)
69
- case type
70
- when "Time"
71
- Time.at(value)
78
+ case value
79
+ when ::Array
80
+ value.collect do |element|
81
+ convert_value(element, type)
82
+ end
72
83
  else
73
- value
84
+ case type
85
+ when "Time"
86
+ Time.at(value)
87
+ else
88
+ value
89
+ end
74
90
  end
75
91
  end
76
92
 
77
- def parse_match_records(raw_records)
78
- parse_result(raw_records)
93
+ def parse_match_records_v1(raw_records)
94
+ [
95
+ raw_records.first.first,
96
+ parse_records(raw_records[1], raw_records[2..-1]),
97
+ ]
79
98
  end
80
99
 
81
- def parse_drilldowns(raw_drilldowns)
100
+ def parse_match_records_v3(raw_records)
101
+ [
102
+ raw_records["n_hits"],
103
+ parse_records(raw_records["columns"], raw_records["records"]),
104
+ ]
105
+ end
106
+
107
+ def parse_drilldowns_v1(raw_drilldowns)
82
108
  (raw_drilldowns || []).collect.with_index do |raw_drilldown, i|
83
109
  key = @command.drilldowns[i]
84
- n_hits, items = parse_result(raw_drilldown)
85
- Drilldown.new(key, n_hits, items)
110
+ n_hits, records = parse_match_records_v1(raw_drilldown)
111
+ Drilldown.new(key, n_hits, records)
112
+ end
113
+ end
114
+
115
+ def parse_drilldowns_v3(raw_drilldowns)
116
+ (raw_drilldowns || {}).collect do |(key, raw_drilldown)|
117
+ n_hits, records = parse_match_records_v3(raw_drilldown)
118
+ Drilldown.new(key, n_hits, records)
86
119
  end
87
120
  end
88
121
 
89
- class Drilldown < Struct.new(:key, :n_hits, :items)
122
+ class Drilldown < Struct.new(:key, :n_hits, :records)
123
+ # @deprecated since 0.2.6. Use {#records} instead.
124
+ alias_method :items, :records
90
125
  end
91
126
  end
92
127
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  class Client
19
- VERSION = "0.2.5"
19
+ VERSION = "0.2.6"
20
20
  end
21
21
  end
@@ -18,95 +18,194 @@ require "response/helper"
18
18
 
19
19
  class TestResponseBase < Test::Unit::TestCase
20
20
  class TestHeader < self
21
- class TestStatusCode < self
22
- def test_have_header
23
- header = [
24
- -21,
25
- 1396012478.14975,
26
- 0.00050806999206543,
27
- ]
28
- response = Groonga::Client::Response::Base.new(nil, header, nil)
29
- assert_equal(-21, response.status_code)
30
- end
21
+ class TestCommandVersion1 < self
22
+ class TestReturnCode < self
23
+ def test_have_header
24
+ header = [
25
+ -21,
26
+ 1396012478.14975,
27
+ 0.00050806999206543,
28
+ ]
29
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
30
+ assert_equal(-21, response.return_code)
31
+ end
31
32
 
32
- def test_no_header
33
- response = Groonga::Client::Response::Error.new(nil, nil, nil)
34
- assert_equal(0, response.status_code)
33
+ def test_no_header
34
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
35
+ assert_equal(0, response.return_code)
36
+ end
35
37
  end
36
- end
37
38
 
38
- class TestStartTime < self
39
- def test_have_header
40
- start_time = 1396012478.14975
41
- header = [
42
- -21,
43
- start_time,
44
- 0.00050806999206543,
45
- ]
46
- response = Groonga::Client::Response::Base.new(nil, header, nil)
47
- assert_equal(Time.at(start_time), response.start_time)
39
+ class TestStartTime < self
40
+ def test_have_header
41
+ start_time = 1396012478.14975
42
+ header = [
43
+ -21,
44
+ start_time,
45
+ 0.00050806999206543,
46
+ ]
47
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
48
+ assert_equal(Time.at(start_time), response.start_time)
49
+ end
50
+
51
+ def test_no_header
52
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
53
+ assert_equal(Time.at(0), response.start_time)
54
+ end
48
55
  end
49
56
 
50
- def test_no_header
51
- response = Groonga::Client::Response::Error.new(nil, nil, nil)
52
- assert_equal(Time.at(0), response.start_time)
57
+ class TestElapsedTime < self
58
+ def test_have_header
59
+ elapsed_time = 0.00050806999206543
60
+ header = [
61
+ -21,
62
+ 1396012478.14975,
63
+ elapsed_time,
64
+ ]
65
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
66
+ assert_equal(elapsed_time, response.elapsed_time)
67
+ end
68
+
69
+ def test_no_header
70
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
71
+ assert_equal(0.0, response.elapsed_time)
72
+ end
53
73
  end
54
- end
55
74
 
56
- class TestElapsedTime < self
57
- def test_have_header
58
- elapsed_time = 0.00050806999206543
59
- header = [
60
- -21,
61
- 1396012478.14975,
62
- elapsed_time,
63
- ]
64
- response = Groonga::Client::Response::Base.new(nil, header, nil)
65
- assert_equal(elapsed_time, response.elapsed_time)
75
+ class TestErrorMessage < self
76
+ def test_have_header
77
+ error_message = "invalid argument"
78
+ header = [
79
+ -21,
80
+ 1396012478.14975,
81
+ 0.00050806999206543,
82
+ error_message,
83
+ ]
84
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
85
+ assert_equal(error_message, response.error_message)
86
+ end
87
+
88
+ def test_no_header
89
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
90
+ assert_nil(response.error_message)
91
+ end
66
92
  end
67
93
 
68
- def test_no_header
69
- response = Groonga::Client::Response::Error.new(nil, nil, nil)
70
- assert_equal(0.0, response.elapsed_time)
94
+ class TestSuccess < self
95
+ def test_have_header
96
+ header = [
97
+ -21,
98
+ 1396012478.14975,
99
+ 0.00050806999206543,
100
+ ]
101
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
102
+ assert do
103
+ not response.success?
104
+ end
105
+ end
106
+
107
+ def test_no_header
108
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
109
+ assert do
110
+ response.success?
111
+ end
112
+ end
71
113
  end
72
114
  end
73
115
 
74
- class TestErrorMessage < self
75
- def test_have_header
76
- error_message = "invalid argument"
77
- header = [
78
- -21,
79
- 1396012478.14975,
80
- 0.00050806999206543,
81
- error_message,
82
- ]
83
- response = Groonga::Client::Response::Base.new(nil, header, nil)
84
- assert_equal(error_message, response.error_message)
116
+ class TestCommandVersion3 < self
117
+ class TestReturnCode < self
118
+ def test_have_header
119
+ header = {
120
+ "return_code" => -21,
121
+ "start_time" => 1396012478.14975,
122
+ "elapsed_time" => 0.00050806999206543,
123
+ }
124
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
125
+ assert_equal(-21, response.return_code)
126
+ end
127
+
128
+ def test_no_header
129
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
130
+ assert_equal(0, response.return_code)
131
+ end
85
132
  end
86
133
 
87
- def test_no_header
88
- response = Groonga::Client::Response::Error.new(nil, nil, nil)
89
- assert_nil(response.error_message)
134
+ class TestStartTime < self
135
+ def test_have_header
136
+ start_time = 1396012478.14975
137
+ header = {
138
+ "return_code" => -21,
139
+ "start_time" => start_time,
140
+ "elapsed_time" => 0.00050806999206543,
141
+ }
142
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
143
+ assert_equal(Time.at(start_time), response.start_time)
144
+ end
145
+
146
+ def test_no_header
147
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
148
+ assert_equal(Time.at(0), response.start_time)
149
+ end
150
+ end
151
+
152
+ class TestElapsedTime < self
153
+ def test_have_header
154
+ elapsed_time = 0.00050806999206543
155
+ header = {
156
+ "return_code" => -21,
157
+ "start_time" => 1396012478.14975,
158
+ "elapsed_time" => elapsed_time,
159
+ }
160
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
161
+ assert_equal(elapsed_time, response.elapsed_time)
162
+ end
163
+
164
+ def test_no_header
165
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
166
+ assert_equal(0.0, response.elapsed_time)
167
+ end
90
168
  end
91
- end
92
169
 
93
- class TestSuccess < self
94
- def test_have_header
95
- header = [
96
- -21,
97
- 1396012478.14975,
98
- 0.00050806999206543,
99
- ]
100
- response = Groonga::Client::Response::Base.new(nil, header, nil)
101
- assert do
102
- not response.success?
170
+ class TestErrorMessage < self
171
+ def test_have_header
172
+ error_message = "invalid argument"
173
+ header = {
174
+ "return_code" => -21,
175
+ "start_time" => 1396012478.14975,
176
+ "elapsed_time" => 0.00050806999206543,
177
+ "error" => {
178
+ "message" => error_message,
179
+ },
180
+ }
181
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
182
+ assert_equal(error_message, response.error_message)
183
+ end
184
+
185
+ def test_no_header
186
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
187
+ assert_nil(response.error_message)
103
188
  end
104
189
  end
105
190
 
106
- def test_no_header
107
- response = Groonga::Client::Response::Error.new(nil, nil, nil)
108
- assert do
109
- response.success?
191
+ class TestSuccess < self
192
+ def test_have_header
193
+ header = {
194
+ "return_code" => -21,
195
+ "start_time" => 1396012478.14975,
196
+ "elapsed_time" => 0.00050806999206543,
197
+ }
198
+ response = Groonga::Client::Response::Base.new(nil, header, nil)
199
+ assert do
200
+ not response.success?
201
+ end
202
+ end
203
+
204
+ def test_no_header
205
+ response = Groonga::Client::Response::Error.new(nil, nil, nil)
206
+ assert do
207
+ response.success?
208
+ end
110
209
  end
111
210
  end
112
211
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
2
2
  # Copyright (C) 2013 Kosuke Asami
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
17
17
 
18
18
  require "response/helper"
19
19
 
20
- class TestResponseSelect < Test::Unit::TestCase
20
+ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
21
21
  class TestParseRawResponse < self
22
22
  include TestResponseHelper
23
23
 
@@ -54,6 +54,30 @@ class TestResponseSelect < Test::Unit::TestCase
54
54
  records([[[1], [["updated_at", "Time"]], [updated_at]]]))
55
55
  end
56
56
 
57
+ def test_time_vector
58
+ update1 = 1379040474
59
+ update2 = 1464598349
60
+ assert_equal([
61
+ {
62
+ "updates" => [
63
+ Time.at(update1),
64
+ Time.at(update2),
65
+ ],
66
+ },
67
+ ],
68
+ records([
69
+ [
70
+ [1],
71
+ [
72
+ ["updates", "Time"],
73
+ ],
74
+ [
75
+ [update1, update2],
76
+ ],
77
+ ]
78
+ ]))
79
+ end
80
+
57
81
  def test_duplicated_column_name
58
82
  assert_equal([
59
83
  {
@@ -88,7 +112,7 @@ class TestResponseSelect < Test::Unit::TestCase
88
112
  class TestDrilldowns < self
89
113
  def setup
90
114
  pair_arguments = {
91
- "drilldown" => "_key",
115
+ "drilldown" => "tag",
92
116
  "drilldown_output_columns" => "_key,_nsubrecs",
93
117
  }
94
118
  @command = Groonga::Command::Select.new("select", pair_arguments)
@@ -108,7 +132,7 @@ class TestResponseSelect < Test::Unit::TestCase
108
132
  ["rroonga", 9],
109
133
  ],
110
134
  ]
111
- assert_equal(["_key"],
135
+ assert_equal(["tag"],
112
136
  drilldowns(body).collect(&:key))
113
137
  end
114
138
 
@@ -0,0 +1,274 @@
1
+ # Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2013 Kosuke Asami
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require "response/helper"
19
+
20
+ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
21
+ class TestParseRawResponse < self
22
+ include TestResponseHelper
23
+
24
+ def test_select
25
+ header = {
26
+ "return_code" => 0,
27
+ "start_time" => 1372430096.70991,
28
+ "elapsed_time" => 0.000522851943969727,
29
+ }
30
+ body = {
31
+ "n_hits" => 1,
32
+ "columns" => [
33
+ {
34
+ "name" => "_id",
35
+ "type" => "UInt32",
36
+ },
37
+ ],
38
+ "records" => [
39
+ 1,
40
+ ],
41
+ }
42
+ raw_response = {
43
+ "header" => header,
44
+ "body" => body,
45
+ }.to_json
46
+
47
+ response = parse_raw_response("select", raw_response)
48
+ assert_equal(Groonga::Client::Response::Select, response.class)
49
+ end
50
+ end
51
+
52
+ class TestBody < self
53
+ def setup
54
+ @command = Groonga::Command::Select.new("select", {})
55
+ end
56
+
57
+ def test_n_hits
58
+ response = create_response({
59
+ "n_hits" => 29,
60
+ "columns" => [
61
+ {
62
+ "name" => "_id",
63
+ "type" => "UInt32",
64
+ },
65
+ ],
66
+ "records" => [
67
+ ],
68
+ })
69
+ assert_equal(29, response.n_hits)
70
+ end
71
+
72
+ private
73
+ def create_response(body)
74
+ header = {
75
+ "return_code" => 0,
76
+ "start_time" => 1372430096.70991,
77
+ "elapsed_time" => 0.000522851943969727,
78
+ }
79
+ Groonga::Client::Response::Select.new(@command, header, body)
80
+ end
81
+
82
+ class TestRecords < self
83
+ def test_time
84
+ updated_at = 1379040474
85
+ assert_equal([{"updated_at" => Time.at(updated_at)}],
86
+ records({
87
+ "n_hits" => 1,
88
+ "columns" => [
89
+ {
90
+ "name" => "updated_at",
91
+ "type" => "Time",
92
+ },
93
+ ],
94
+ "records" => [
95
+ [updated_at],
96
+ ],
97
+ }))
98
+ end
99
+
100
+ def test_time_vector
101
+ update1 = 1379040474
102
+ update2 = 1464598349
103
+ assert_equal([
104
+ {
105
+ "updates" => [
106
+ Time.at(update1),
107
+ Time.at(update2),
108
+ ],
109
+ },
110
+ ],
111
+ records({
112
+ "n_hits" => 1,
113
+ "columns" => [
114
+ {
115
+ "name" => "updates",
116
+ "type" => "Time",
117
+ },
118
+ ],
119
+ "records" => [
120
+ [
121
+ [update1, update2],
122
+ ],
123
+ ],
124
+ }))
125
+ end
126
+
127
+ def test_duplicated_column_name
128
+ assert_equal([
129
+ {
130
+ "html_escape" => "content1",
131
+ "html_escape2" => "content2",
132
+ "html_escape3" => "content3",
133
+ }
134
+ ],
135
+ records({
136
+ "n_hits" => 1,
137
+ "columns" => [
138
+ {
139
+ "name" => "html_escape",
140
+ "type" => nil,
141
+ },
142
+ {
143
+ "name" => "html_escape",
144
+ "type" => nil,
145
+ },
146
+ {
147
+ "name" => "html_escape",
148
+ "type" => nil,
149
+ }
150
+ ],
151
+ "records" => [
152
+ ["content1", "content2", "content3"],
153
+ ],
154
+ }))
155
+ end
156
+
157
+ private
158
+ def records(body)
159
+ create_response(body).records
160
+ end
161
+ end
162
+
163
+ class TestDrilldowns < self
164
+ def setup
165
+ pair_arguments = {
166
+ "drilldown" => "tag",
167
+ "drilldown_output_columns" => "_key,_nsubrecs",
168
+ }
169
+ @command = Groonga::Command::Select.new("select", pair_arguments)
170
+ end
171
+
172
+ def test_key
173
+ body = {
174
+ "n_hits" => 0,
175
+ "columns" => [],
176
+ "records" => [],
177
+ "drilldowns" => {
178
+ "tag" => {
179
+ "n_hits" => 29,
180
+ "columns" => [
181
+ {
182
+ "name" => "_key",
183
+ "type" => "ShortText",
184
+ },
185
+ {
186
+ "name" => "_nsubrecs",
187
+ "type" => "Int32",
188
+ },
189
+ ],
190
+ "records" => [
191
+ ["groonga", 29],
192
+ ["Ruby", 19],
193
+ ["rroonga", 9],
194
+ ],
195
+ },
196
+ },
197
+ }
198
+ assert_equal(["tag"],
199
+ drilldowns(body).collect(&:key))
200
+ end
201
+
202
+ def test_n_hits
203
+ body = {
204
+ "n_hits" => 0,
205
+ "columns" => [],
206
+ "records" => [],
207
+ "drilldowns" => {
208
+ "tag" => {
209
+ "n_hits" => 29,
210
+ "columns" => [
211
+ {
212
+ "name" => "_key",
213
+ "type" => "ShortText",
214
+ },
215
+ {
216
+ "name" => "_nsubrecs",
217
+ "type" => "Int32",
218
+ },
219
+ ],
220
+ "records" => [
221
+ ["groonga", 29],
222
+ ["Ruby", 19],
223
+ ["rroonga", 9],
224
+ ],
225
+ },
226
+ },
227
+ }
228
+ assert_equal([29],
229
+ drilldowns(body).collect(&:n_hits))
230
+ end
231
+
232
+ def test_items
233
+ body = {
234
+ "n_hits" => 0,
235
+ "columns" => [],
236
+ "records" => [],
237
+ "drilldowns" => {
238
+ "tag" => {
239
+ "n_hits" => 29,
240
+ "columns" => [
241
+ {
242
+ "name" => "_key",
243
+ "type" => "ShortText",
244
+ },
245
+ {
246
+ "name" => "_nsubrecs",
247
+ "type" => "Int32",
248
+ },
249
+ ],
250
+ "records" => [
251
+ ["groonga", 29],
252
+ ["Ruby", 19],
253
+ ["rroonga", 9],
254
+ ],
255
+ },
256
+ },
257
+ }
258
+ assert_equal([
259
+ [
260
+ {"_key" => "groonga", "_nsubrecs" => 29},
261
+ {"_key" => "Ruby", "_nsubrecs" => 19},
262
+ {"_key" => "rroonga", "_nsubrecs" => 9},
263
+ ],
264
+ ],
265
+ drilldowns(body).collect(&:items))
266
+ end
267
+
268
+ private
269
+ def drilldowns(body)
270
+ create_response(body).drilldowns
271
+ end
272
+ end
273
+ end
274
+ end
data/test/run-test.rb CHANGED
@@ -41,7 +41,6 @@ test_dir = base_dir + "test"
41
41
  $LOAD_PATH.unshift(lib_dir.to_s)
42
42
 
43
43
  require "test-unit"
44
- require "test/unit/notify"
45
44
 
46
45
  Thread.abort_on_exception = true
47
46
 
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.2.5
4
+ version: 0.2.6
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: 2016-04-01 00:00:00.000000000 Z
13
+ date: 2016-06-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gqtp
@@ -96,20 +96,6 @@ dependencies:
96
96
  - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
- - !ruby/object:Gem::Dependency
100
- name: test-unit-notify
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
99
  - !ruby/object:Gem::Dependency
114
100
  name: test-unit-rr
115
101
  requirement: !ruby/object:Gem::Requirement
@@ -232,7 +218,8 @@ files:
232
218
  - test/response/test-column-list.rb
233
219
  - test/response/test-error.rb
234
220
  - test/response/test-schema.rb
235
- - test/response/test-select.rb
221
+ - test/response/test-select-command-version1.rb
222
+ - test/response/test-select-command-version3.rb
236
223
  - test/response/test-status.rb
237
224
  - test/response/test-table-create.rb
238
225
  - test/response/test-table-list.rb
@@ -282,7 +269,8 @@ test_files:
282
269
  - test/response/test-table-list.rb
283
270
  - test/response/test-status.rb
284
271
  - test/response/test-schema.rb
285
- - test/response/test-select.rb
272
+ - test/response/test-select-command-version3.rb
273
+ - test/response/test-select-command-version1.rb
286
274
  - test/response/test-table-create.rb
287
275
  - test/response/test-table-remove.rb
288
276
  - test/results/test-column-list.rb