groonga-client 0.5.8 → 0.6.3

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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2019 Sutou Kouhei <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.5.8"
19
+ VERSION = "0.6.3"
20
20
  end
21
21
  end
@@ -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
@@ -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
@@ -55,7 +55,7 @@ class TestResponseError < Test::Unit::TestCase
55
55
 
56
56
  def test_no_header
57
57
  response = Groonga::Client::Response::Error.new(nil, nil, nil)
58
- assert_equal("", response.message)
58
+ assert_nil(response.message)
59
59
  end
60
60
  end
61
61
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2020 Sutou Kouhei <kou@clear-code.com>
2
2
  # Copyright (C) 2013 Kosuke Asami
3
3
  # Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
4
4
  #
@@ -320,12 +320,14 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
320
320
  class TestSlices < self
321
321
  def setup
322
322
  pair_arguments = {
323
- "slices[groonga].filter" => 'tag @ "groonga"',
323
+ "slices[groonga].filter" => "tag @ 'groonga'",
324
+ "slices[groonga].limit" => "2",
325
+ "slices[groonga].drilldowns[author].keys" => "author",
324
326
  }
325
327
  @command = Groonga::Command::Select.new("select", pair_arguments)
326
328
  @body = [
327
329
  [
328
- [3],
330
+ [4],
329
331
  [
330
332
  [
331
333
  "_id",
@@ -339,10 +341,11 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
339
341
  [1, "groonga"],
340
342
  [2, "rroonga"],
341
343
  [3, "groonga"],
344
+ [4, "groonga"],
342
345
  ],
343
346
  {
344
347
  "groonga" => [
345
- [2],
348
+ [3],
346
349
  [
347
350
  [
348
351
  "_id",
@@ -355,19 +358,55 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
355
358
  ],
356
359
  [1, "groonga"],
357
360
  [3, "groonga"],
358
- ]
359
- }
361
+ {
362
+ "author" => [
363
+ [3],
364
+ [
365
+ [
366
+ "_key",
367
+ "ShortText",
368
+ ],
369
+ [
370
+ "_nsubrecs",
371
+ "Int32",
372
+ ],
373
+ ],
374
+ [
375
+ "Alice",
376
+ 1,
377
+ ],
378
+ [
379
+ "Bob",
380
+ 1,
381
+ ],
382
+ [
383
+ "Chris",
384
+ 1,
385
+ ],
386
+ ],
387
+ },
388
+ ],
389
+ },
360
390
  ]
361
391
  end
362
392
 
363
393
  def test_slices
364
394
  assert_equal({
365
- "groonga" => [
366
- {"_id" => 1, "tag" => "groonga"},
367
- {"_id" => 3, "tag" => "groonga"},
368
- ]
395
+ "groonga" => {
396
+ records: [
397
+ {"_id" => 1, "tag" => "groonga"},
398
+ {"_id" => 3, "tag" => "groonga"},
399
+ ],
400
+ drilldowns: {
401
+ "author" => [
402
+ {"_key" => "Alice", "_nsubrecs" => 1},
403
+ {"_key" => "Bob", "_nsubrecs" => 1},
404
+ {"_key" => "Chris", "_nsubrecs" => 1},
405
+ ],
406
+ },
407
+ },
369
408
  },
370
- collect_values(@body, &:records))
409
+ collect_values(@body))
371
410
  end
372
411
 
373
412
  private
@@ -378,7 +417,14 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase
378
417
  def collect_values(body)
379
418
  values = {}
380
419
  slices(body).each do |label, slice|
381
- values[label] = yield(slice)
420
+ drilldowns = {}
421
+ slice.drilldowns.each do |drilldown_label, drilldown|
422
+ drilldowns[drilldown_label] = drilldown.records
423
+ end
424
+ values[label] = {
425
+ records: slice.records,
426
+ drilldowns: drilldowns,
427
+ }
382
428
  end
383
429
  values
384
430
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2020 Sutou Kouhei <kou@clear-code.com>
2
2
  # Copyright (C) 2013 Kosuke Asami
3
3
  # Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
4
4
  #
@@ -284,6 +284,7 @@ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
284
284
  def setup
285
285
  pair_arguments = {
286
286
  "slices[groonga].filter" => 'tag @ "groonga"',
287
+ "slices[groonga].drilldowns[author].keys" => "author",
287
288
  }
288
289
  @command = Groonga::Command::Select.new("select", pair_arguments)
289
290
  @body = {
@@ -319,7 +320,36 @@ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
319
320
  "records" => [
320
321
  [1, "groonga"],
321
322
  [3, "groonga"],
322
- ]
323
+ ],
324
+ "drilldowns" => {
325
+ "author" => {
326
+ "n_hits" => 3,
327
+ "columns" => [
328
+ {
329
+ "name" => "_key",
330
+ "type" => "ShortText",
331
+ },
332
+ {
333
+ "name" => "_nsubrecs",
334
+ "type" => "Int32",
335
+ },
336
+ ],
337
+ "records" => [
338
+ [
339
+ "Alice",
340
+ 1,
341
+ ],
342
+ [
343
+ "Bob",
344
+ 1,
345
+ ],
346
+ [
347
+ "Chris",
348
+ 1,
349
+ ],
350
+ ],
351
+ },
352
+ },
323
353
  }
324
354
  }
325
355
  }
@@ -327,12 +357,21 @@ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
327
357
 
328
358
  def test_slices
329
359
  assert_equal({
330
- "groonga" => [
331
- {"_id" => 1, "tag" => "groonga"},
332
- {"_id" => 3, "tag" => "groonga"},
333
- ]
360
+ "groonga" => {
361
+ records: [
362
+ {"_id" => 1, "tag" => "groonga"},
363
+ {"_id" => 3, "tag" => "groonga"},
364
+ ],
365
+ drilldowns: {
366
+ "author" => [
367
+ {"_key" => "Alice", "_nsubrecs" => 1},
368
+ {"_key" => "Bob", "_nsubrecs" => 1},
369
+ {"_key" => "Chris", "_nsubrecs" => 1},
370
+ ],
371
+ },
372
+ },
334
373
  },
335
- collect_values(@body, &:records))
374
+ collect_values(@body))
336
375
  end
337
376
 
338
377
  private
@@ -343,7 +382,14 @@ class TestResponseSelectCommandVersion3 < Test::Unit::TestCase
343
382
  def collect_values(body)
344
383
  values = {}
345
384
  slices(body).each do |label, slice|
346
- values[label] = yield(slice)
385
+ drilldowns = {}
386
+ slice.drilldowns.each do |drilldown_label, drilldown|
387
+ drilldowns[drilldown_label] = drilldown.records
388
+ end
389
+ values[label] = {
390
+ records: slice.records,
391
+ drilldowns: drilldowns,
392
+ }
347
393
  end
348
394
  values
349
395
  end
@@ -0,0 +1,149 @@
1
+ # Copyright (C) 2018-2019 Sutou Kouhei <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(label,
23
+ keys,
24
+ n_hits,
25
+ records,
26
+ raw_columns,
27
+ raw_records)
28
+ Groonga::Client::Response::Select::Drilldown.new(label,
29
+ keys,
30
+ n_hits,
31
+ records,
32
+ raw_columns,
33
+ raw_records)
34
+ end
35
+
36
+ def test_error
37
+ raw_response = <<-TSV
38
+ -22 0 0.0 "message" "function" "file" 29
39
+
40
+ END
41
+ TSV
42
+
43
+ response = parse_raw_tsv_response("select", raw_response)
44
+ assert_equal({
45
+ :return_code => -22,
46
+ :start_time => Time.at(0),
47
+ :elapsed_time => 0.0,
48
+ :error => {
49
+ :message => "message",
50
+ :function => "function",
51
+ :file => "file",
52
+ :line => 29,
53
+ },
54
+ },
55
+ {
56
+ :return_code => response.return_code,
57
+ :start_time => response.start_time,
58
+ :elapsed_time => response.elapsed_time,
59
+ :error => {
60
+ :message => response.message,
61
+ :function => response.function,
62
+ :file => response.file,
63
+ :line => response.line,
64
+ },
65
+ })
66
+ end
67
+
68
+ def test_basic
69
+ raw_response = <<-TSV
70
+ 0 0 0.0
71
+ 100
72
+ [ "_id" "UInt32" ]
73
+ 1
74
+ 2
75
+ END
76
+ TSV
77
+
78
+ response = parse_raw_tsv_response("select", raw_response)
79
+ assert_equal({
80
+ :return_code => 0,
81
+ :start_time => Time.at(0),
82
+ :elapsed_time => 0.0,
83
+ :records => [
84
+ {"_id" => "1"},
85
+ {"_id" => "2"},
86
+ ],
87
+ },
88
+ {
89
+ :return_code => response.return_code,
90
+ :start_time => response.start_time,
91
+ :elapsed_time => response.elapsed_time,
92
+ :records => response.records,
93
+ })
94
+ end
95
+
96
+ def test_drilldown
97
+ raw_response = <<-TSV
98
+ 0 0 0.0
99
+ 100
100
+ [ "_id" "UInt32" ]
101
+ 7
102
+ [ "_key" "ShortText" ] [ "_nsubrecs" "UInt32" ]
103
+ "2.2.0" "18044"
104
+ "2.3.0" "18115"
105
+ "2.4.0" "14594"
106
+ END
107
+ TSV
108
+
109
+ response = parse_raw_response_raw("select",
110
+ {
111
+ "drilldown" => "version",
112
+ "output_type" => "tsv",
113
+ },
114
+ raw_response)
115
+ drilldown_records = [
116
+ {"_key" => "2.2.0", "_nsubrecs" => "18044"},
117
+ {"_key" => "2.3.0", "_nsubrecs" => "18115"},
118
+ {"_key" => "2.4.0", "_nsubrecs" => "14594"},
119
+ ]
120
+ assert_equal({
121
+ :return_code => 0,
122
+ :start_time => Time.at(0),
123
+ :elapsed_time => 0.0,
124
+ :records => [],
125
+ :drilldowns => [
126
+ drilldown("version",
127
+ ["version"],
128
+ 7,
129
+ drilldown_records,
130
+ [
131
+ ["_key", "ShortText"],
132
+ ["_nsubrecs", "UInt32"],
133
+ ],
134
+ [
135
+ ["2.2.0", "18044"],
136
+ ["2.3.0", "18115"],
137
+ ["2.4.0", "14594"],
138
+ ]),
139
+ ],
140
+ },
141
+ {
142
+ :return_code => response.return_code,
143
+ :start_time => response.start_time,
144
+ :elapsed_time => response.elapsed_time,
145
+ :records => response.records,
146
+ :drilldowns => response.drilldowns,
147
+ })
148
+ end
149
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2017-2019 Sutou Kouhei <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
@@ -19,8 +19,18 @@ require "response/helper"
19
19
  class TestResponseSelectXML < Test::Unit::TestCase
20
20
  include TestResponseHelper
21
21
 
22
- def drilldown(key, n_hits, records)
23
- Groonga::Client::Response::Select::Drilldown.new(key, n_hits, records)
22
+ def drilldown(label,
23
+ keys,
24
+ n_hits,
25
+ records,
26
+ raw_columns,
27
+ raw_records)
28
+ Groonga::Client::Response::Select::Drilldown.new(label,
29
+ keys,
30
+ n_hits,
31
+ records,
32
+ raw_columns,
33
+ raw_records)
24
34
  end
25
35
 
26
36
  def test_basic
@@ -91,7 +101,19 @@ class TestResponseSelectXML < Test::Unit::TestCase
91
101
  :elapsed_time => 0.0,
92
102
  :records => [],
93
103
  :drilldowns => [
94
- drilldown("version", 7, drilldown_records),
104
+ drilldown("version",
105
+ ["version"],
106
+ 7,
107
+ drilldown_records,
108
+ [
109
+ ["_key", "ShortText"],
110
+ ["_nsubrecs", "ShortText"],
111
+ ],
112
+ [
113
+ ["2.2.0", "18044"],
114
+ ["2.3.0", "18115"],
115
+ ["2.4.0", "14594"],
116
+ ]),
95
117
  ],
96
118
  },
97
119
  {