fluent-plugin-mysql 0.2.0 → 0.2.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: 6c8d2f2fd5a6164a01413ca4d9179d6a93d8b4f0
4
- data.tar.gz: 05a99dbf24a3458cbd2031f87da2b1cd154c7d66
3
+ metadata.gz: 9859ad599cbae8698e0054adcbeaff3205f5a537
4
+ data.tar.gz: 96cdfad1bf8d00270b2e6ac9d8ac92b83987b326
5
5
  SHA512:
6
- metadata.gz: 1aaf277b0400baf6235a2a1ebfa954e55c3f1b09f63c81f524f1d8af2751eb9e53de9f0828630de1e2bf8c36468445a51951e88f6823528b18db4716226c0a75
7
- data.tar.gz: f1889ff991d71cc77e0c35201ed8bd169464e118671865ad839717d97082b3e9118c416342f568a2e2506f290760da350034c5e9835cf5120a468a64c1caf774
6
+ metadata.gz: e15db1860fe2d5925917a6fe949459e0d3e75cddd7d57f8df3d83f497f6e55dafa634b3da94273bcae01f2d89c64e5862da4540ec649034ce1a311320b4e88bc
7
+ data.tar.gz: b1d106391be32bb63aa2dde7ade7c894fef44eab820ccf2dd7f9901160a7bfd26629469a8f089eddc80fff2d6f94d8c13a0c0343286f140eba07b987f4bd45fe
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-mysql"
4
- gem.version = "0.2.0"
4
+ gem.version = "0.2.1"
5
5
  gem.authors = ["TAGOMORI Satoshi", "Toyama Hiroshi"]
6
6
  gem.email = ["tagomoris@gmail.com", "toyama0919@gmail.com"]
7
7
  gem.description = %q{fluent plugin to insert mysql as json(single column) or insert statement}
@@ -33,6 +33,8 @@ DESC
33
33
  desc: "On duplicate key update enable."
34
34
  config_param :on_duplicate_update_keys, :string, default: nil,
35
35
  desc: "On duplicate key update column, comma separator."
36
+ config_param :on_duplicate_update_custom_values, :string, default: nil,
37
+ desc: "On_duplicate_update_custom_values, comma separator. specify the column name is insert value, custom value is use ${sql conditions}"
36
38
 
37
39
  attr_accessor :handler
38
40
 
@@ -55,10 +57,25 @@ DESC
55
57
  end
56
58
  @on_duplicate_update_keys = @on_duplicate_update_keys.split(',')
57
59
 
60
+ if !@on_duplicate_update_custom_values.nil?
61
+ @on_duplicate_update_custom_values = @on_duplicate_update_custom_values.split(',')
62
+ if @on_duplicate_update_custom_values.length != @on_duplicate_update_keys.length
63
+ fail Fluent::ConfigError, <<-DESC
64
+ on_duplicate_update_keys and on_duplicate_update_custom_values must be the same length
65
+ DESC
66
+ end
67
+ end
68
+
58
69
  @on_duplicate_key_update_sql = ' ON DUPLICATE KEY UPDATE '
59
70
  updates = []
60
- @on_duplicate_update_keys.each do |update_column|
61
- updates << "#{update_column} = VALUES(#{update_column})"
71
+ @on_duplicate_update_keys.each_with_index do |update_column, i|
72
+ if @on_duplicate_update_custom_values.nil? || @on_duplicate_update_custom_values[i] == "#{update_column}"
73
+ updates << "#{update_column} = VALUES(#{update_column})"
74
+ else
75
+ value = @on_duplicate_update_custom_values[i].to_s.match(/\${(.*)}/)[1]
76
+ escape_value = Mysql2::Client.escape(value)
77
+ updates << "#{update_column} = #{escape_value}"
78
+ end
62
79
  end
63
80
  @on_duplicate_key_update_sql += updates.join(',')
64
81
  end
@@ -158,6 +158,20 @@ class MysqlBulkOutputTest < Test::Unit::TestCase
158
158
  flush_interval 10s
159
159
  ]
160
160
  end
161
+
162
+ assert_raise(Fluent::ConfigError) do
163
+ create_driver %[
164
+ host localhost
165
+ username root
166
+ password hogehoge
167
+ column_names id,user_name,login_count,created_at,updated_at
168
+ table users
169
+ on_duplicate_key_update true
170
+ on_duplicate_update_keys login_count,updated_at
171
+ on_duplicate_update_custom_values login_count
172
+ flush_interval 10s
173
+ ]
174
+ end
161
175
  end
162
176
 
163
177
  def test_configure
@@ -222,6 +236,20 @@ class MysqlBulkOutputTest < Test::Unit::TestCase
222
236
  table access
223
237
  ]
224
238
  end
239
+
240
+ assert_nothing_raised(Fluent::ConfigError) do
241
+ create_driver %[
242
+ database test_app_development
243
+ username root
244
+ password hogehoge
245
+ column_names id,user_name,login_count,created_at,updated_at
246
+ key_names id,user_name,login_count,created_date,updated_date
247
+ table users
248
+ on_duplicate_key_update true
249
+ on_duplicate_update_keys login_count,updated_at
250
+ on_duplicate_update_custom_values ${`login_count` + 1},updated_at
251
+ ]
252
+ end
225
253
  end
226
254
 
227
255
  def test_variables
@@ -281,6 +309,22 @@ class MysqlBulkOutputTest < Test::Unit::TestCase
281
309
  assert_equal ['id','url','request_headers_json','params_json','created_date','updated_date'], d.instance.column_names
282
310
  assert_equal ['request_headers','params'], d.instance.json_key_names
283
311
  assert_nil d.instance.instance_variable_get(:@on_duplicate_key_update_sql)
312
+
313
+ d = create_driver %[
314
+ database test_app_development
315
+ username root
316
+ password hogehoge
317
+ column_names id,user_name,login_count,created_at,updated_at
318
+ table users
319
+ on_duplicate_key_update true
320
+ on_duplicate_update_keys login_count,updated_at
321
+ on_duplicate_update_custom_values ${`login_count` + 1},updated_at
322
+ ]
323
+
324
+ assert_equal ['id','user_name','login_count','created_at','updated_at'], d.instance.key_names
325
+ assert_equal ['id','user_name','login_count','created_at','updated_at'], d.instance.column_names
326
+ assert_equal nil, d.instance.json_key_names
327
+ assert_equal " ON DUPLICATE KEY UPDATE login_count = `login_count` + 1,updated_at = VALUES(updated_at)", d.instance.instance_variable_get(:@on_duplicate_key_update_sql)
284
328
  end
285
329
 
286
330
  def test_spaces_in_columns
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-19 00:00:00.000000000 Z
12
+ date: 2016-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -150,3 +150,4 @@ test_files:
150
150
  - test/helper.rb
151
151
  - test/plugin/test_out_mysql.rb
152
152
  - test/plugin/test_out_mysql_bulk.rb
153
+ has_rdoc: