groonga-command 1.4.0 → 1.4.1

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: 94a17f5c7b56db7a29320cb7af65395183b7a43c
4
- data.tar.gz: 5a199858fd2c1a291bc6fdc4f0e5d76518f19011
3
+ metadata.gz: 90745a99d72f93d9d719234502ba3647dcb1925c
4
+ data.tar.gz: ae6c07674439ffecdccacb23a24522dc342859d5
5
5
  SHA512:
6
- metadata.gz: '0107882a318b6518b8825d68c9c38958b9a98ef3f0e110de7985c848425046e3202ae13a32670353bb99c34a3ac685b697248dabe25ce2747fe3daff0a907bc7'
7
- data.tar.gz: 2f83719bcb481a8a745deca1f3c5337f1f4e6c341f34299f3d03c740e7f9e9a458c07cfe7928cc2c5c30444830ab90ba25549011c09e919915ca082496a2e013
6
+ metadata.gz: bcc65e519bb8f64dfc51dd8b71d4070bcefd3a7a730c2bf96c161d953a9a7da5d5e05b475fbcc8dfca3c2a3f6ee1980455ebccb1aefd1e44d9c21bcb267c41c8
7
+ data.tar.gz: fad54dfbfe207833888e7d7681c9fa9a2109c20aef29cbf602984b048b082e57ef4079e0add7c051755727cbb1165b3e26a4c9b7f77b4fe3d47c5e76fe537fbf
data/doc/text/news.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # News
2
2
 
3
+ ## 1.4.1: 2019-03-26
4
+
5
+ ### Fixes
6
+
7
+ * Fixed a bug that result of conversion to the Elasticsearch
8
+ format result is wrong
9
+
3
10
  ## 1.4.0: 2019-03-20
4
11
 
5
12
  ### Improvements
@@ -156,7 +156,7 @@ module Groonga
156
156
  end
157
157
 
158
158
  def to_elasticsearch_format(options={})
159
- format = Format::Elasticsearch.new(@command_name, normalized_arguments)
159
+ format = Format::Elasticsearch.new(self)
160
160
  format.json(options)
161
161
  end
162
162
 
@@ -18,71 +18,67 @@ module Groonga
18
18
  module Command
19
19
  module Format
20
20
  class Elasticsearch
21
- def initialize(name, arguments)
22
- @name = name
23
- @arguments = arguments
21
+ def initialize(command)
22
+ @command = command
24
23
  end
25
24
 
26
25
  def json(options={})
27
- return nil unless @name == "load"
26
+ return nil unless @command.is_a?(Load)
28
27
 
29
28
  components = []
30
- elasticsearch_version = options[:version] || 5
29
+ action = build_action(options)
30
+ each_source do |source|
31
+ components << JSON.generate(action)
32
+ components << JSON.generate(source)
33
+ end
34
+ components.join("\n")
35
+ end
31
36
 
32
- sorted_arguments = @arguments.sort_by(&:first)
33
- sorted_arguments.each do |name, value|
34
- case name
35
- when :table
36
- case elasticsearch_version
37
- when 7
38
- header = {
39
- "index" => {
40
- "_index" => value.downcase,
41
- "_type"=>"_doc",
42
- }
43
- }
44
- when 8
45
- header = {
46
- "index" => {
47
- "_index" => value.downcase,
48
- }
49
- }
50
- else
51
- # Version 5.x or 6.x
52
- header = {
53
- "index" => {
54
- "_index" => value.downcase,
55
- "_type" => "groonga",
56
- }
57
- }
58
- end
59
- components << JSON.generate(header)
60
- when :values
61
- record = JSON.parse(value)
37
+ private
38
+ def elasticsearch_version(options)
39
+ options[:version] || 5
40
+ end
62
41
 
63
- if record[0].is_a?(::Array)
64
- column_names = nil
42
+ def build_action(options)
43
+ index_name = @command.table.downcase
44
+ case elasticsearch_version(options)
45
+ when 5, 6
46
+ {
47
+ "index" => {
48
+ "_index" => index_name,
49
+ "_type" => "groonga",
50
+ }
51
+ }
52
+ when 7
53
+ {
54
+ "index" => {
55
+ "_index" => index_name,
56
+ "_type"=>"_doc",
57
+ }
58
+ }
59
+ else
60
+ {
61
+ "index" => {
62
+ "_index" => index_name,
63
+ }
64
+ }
65
+ end
66
+ end
65
67
 
66
- record.each do |load_value|
67
- if column_names.nil?
68
- column_names = load_value
69
- next
70
- end
71
- body = {}
72
- column_values = load_value
73
- column_names.zip(column_values) do |column_name, column_value|
74
- body[column_name] = column_value
75
- end
76
- components << JSON.generate(body)
77
- end
68
+ def each_source
69
+ columns = @command.columns
70
+ values = @command.values || []
71
+ values.each do |value|
72
+ if value.is_a?(::Array)
73
+ if columns.nil?
74
+ columns = value
78
75
  else
79
- record.each do |load_value|
80
- components << JSON.generate(load_value)
81
- end
76
+ yield(Hash[columns.zip(value)])
82
77
  end
78
+ else
79
+ yield(value)
83
80
  end
84
81
  end
85
- components.join("\n")
86
82
  end
87
83
  end
88
84
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  module Command
19
- VERSION = "1.4.0"
19
+ VERSION = "1.4.1"
20
20
  end
21
21
  end
@@ -134,13 +134,53 @@ select \\
134
134
  end
135
135
  end
136
136
 
137
+ sub_test_case("no use :columns") do
138
+ def single_record
139
+ load = Groonga::Command::Load.new("load",
140
+ :table => "Site",
141
+ :values => <<-VALUES)
142
+ [
143
+ ["_key", "title"]
144
+ ["http://example.org/","This is test record 1!"]
145
+ ]
146
+ VALUES
147
+
148
+ expected = <<-OUTPUT.chomp
149
+ {"index":{"_index":"site","_type":"groonga"}}
150
+ {"_key":"http://example.org/","title":"This is test record 1!"}
151
+ OUTPUT
152
+
153
+ assert_equal(expected, load.to_elasticsearch_format)
154
+ end
155
+
156
+ def multiple_records
157
+ load = Groonga::Command::Load.new("load",
158
+ :table => "Site",
159
+ :columns => "_key,title",
160
+ :values => <<-VALUES)
161
+ [
162
+ ["http://example.org/","This is test record 1!"],
163
+ ["http://example.net/","This is test record 2!"]
164
+ ]
165
+ VALUES
166
+
167
+ expected = <<-OUTPUT.chomp
168
+ {"index":{"_index":"site","_type":"groonga"}}
169
+ {"_key":"http://example.org/","title":"This is test record 1!"}
170
+ {"_key":"http://example.net/","title":"This is test record 2!"}
171
+ OUTPUT
172
+
173
+ assert_equal(expected, load.to_elasticsearch_format)
174
+ end
175
+ end
176
+
137
177
  sub_test_case("single record") do
138
178
  def test_brackets_format
139
- load = Groonga::Command::Base.new("load",
179
+ load = Groonga::Command::Load.new("load",
140
180
  :table => "Site",
181
+ :columns => "_key,title",
141
182
  :values => <<-VALUES)
142
183
  [
143
- ["_key","title"],
144
184
  ["http://example.org/","This is test record 1!"]
145
185
  ]
146
186
  VALUES
@@ -154,7 +194,7 @@ select \\
154
194
  end
155
195
 
156
196
  def test_curly_brackets_format
157
- load = Groonga::Command::Base.new("load",
197
+ load = Groonga::Command::Load.new("load",
158
198
  :table => "Site",
159
199
  :values => <<-VALUES)
160
200
  [
@@ -173,11 +213,11 @@ select \\
173
213
 
174
214
  sub_test_case("multiple records") do
175
215
  def test_brackets_format
176
- load = Groonga::Command::Base.new("load",
216
+ load = Groonga::Command::Load.new("load",
177
217
  :table => "Site",
218
+ :columns => "_key,title",
178
219
  :values => <<-VALUES)
179
220
  [
180
- ["_key","title"],
181
221
  ["http://example.org/","This is test record 1!"],
182
222
  ["http://example.net/","This is test record 2!"]
183
223
  ]
@@ -186,6 +226,7 @@ select \\
186
226
  expected = <<-OUTPUT.chomp
187
227
  {"index":{"_index":"site","_type":"groonga"}}
188
228
  {"_key":"http://example.org/","title":"This is test record 1!"}
229
+ {"index":{"_index":"site","_type":"groonga"}}
189
230
  {"_key":"http://example.net/","title":"This is test record 2!"}
190
231
  OUTPUT
191
232
 
@@ -193,7 +234,7 @@ select \\
193
234
  end
194
235
 
195
236
  def test_curly_brackets_format
196
- load = Groonga::Command::Base.new("load",
237
+ load = Groonga::Command::Load.new("load",
197
238
  :table => "Site",
198
239
  :values => <<-VALUES)
199
240
  [
@@ -205,6 +246,7 @@ select \\
205
246
  expected = <<-OUTPUT.chomp
206
247
  {"index":{"_index":"site","_type":"groonga"}}
207
248
  {"_key":"http://example.org/","title":"This is test record 1!"}
249
+ {"index":{"_index":"site","_type":"groonga"}}
208
250
  {"_key":"http://example.net/","title":"This is test record 2!"}
209
251
  OUTPUT
210
252
 
@@ -213,11 +255,11 @@ select \\
213
255
  end
214
256
 
215
257
  def setup
216
- @load = Groonga::Command::Base.new("load",
258
+ @load = Groonga::Command::Load.new("load",
217
259
  :table => "Site",
260
+ :columns =>"_key,title",
218
261
  :values => <<-VALUES)
219
262
  [
220
- ["_key","title"],
221
263
  ["http://example.org/","This is test record 1!"]
222
264
  ]
223
265
  VALUES
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json