fluent-plugin-mysql-bulk 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -1
- data/fluent-plugin-mysql-bulk.gemspec +1 -1
- data/lib/fluent/plugin/out_mysql_bulk.rb +6 -7
- data/test/plugin/test_out_mysql_bulk.rb +53 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f577ec221a9e485356e48119e3c72df67d37f2
|
4
|
+
data.tar.gz: 025e392216bd66c322a2f7057356bd92482c9f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0612ab3f00abc23d835c7213b29d412a752845a0a8d4e2a2663c46d55a3bbb8e278cb095ab628a2409e41645a9e90c054f6f8e2c6bf989e8fa060f7f6913f01c
|
7
|
+
data.tar.gz: b9a9a84b4172a2ccd48874621a6980443ecdec9b229ef5b4e422f50fc33dadadfaa8675a8d9e306aa6017d8235aa825512df805ab2a313394e524926d1e7c5bc
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-mysql-bulk"
|
4
|
-
gem.version = "0.0.
|
4
|
+
gem.version = "0.0.8"
|
5
5
|
gem.authors = ["Hiroshi Toyama"]
|
6
6
|
gem.email = ["toyama0919@gmail.com"]
|
7
7
|
gem.description = %q{fluent plugin mysql bulk insert is high performance and on duplicate key update respond.}
|
@@ -39,7 +39,7 @@ module Fluent
|
|
39
39
|
@on_duplicate_key_update_sql = ' ON DUPLICATE KEY UPDATE '
|
40
40
|
updates = []
|
41
41
|
@on_duplicate_update_keys.each do |update_column|
|
42
|
-
updates
|
42
|
+
updates << "#{update_column} = VALUES(#{update_column})"
|
43
43
|
end
|
44
44
|
@on_duplicate_key_update_sql += updates.join(',')
|
45
45
|
end
|
@@ -85,17 +85,16 @@ module Fluent
|
|
85
85
|
|
86
86
|
def write(chunk)
|
87
87
|
@handler = client
|
88
|
-
values_templates = []
|
89
88
|
values = []
|
89
|
+
values_template = "(#{ @column_names.map { |key| '?' }.join(',') })"
|
90
90
|
chunk.msgpack_each do |tag, time, data|
|
91
|
-
|
92
|
-
values.concat(data)
|
91
|
+
values << Mysql2::Client.pseudo_bind(values_template, data)
|
93
92
|
end
|
94
|
-
sql = "INSERT INTO #{@table} (#{@column_names.join(',')}) VALUES #{
|
93
|
+
sql = "INSERT INTO #{@table} (#{@column_names.join(',')}) VALUES #{values.join(',')}"
|
95
94
|
sql += @on_duplicate_key_update_sql if @on_duplicate_key_update
|
96
95
|
|
97
|
-
$log.info "bulk insert values size => #{
|
98
|
-
@handler.xquery(sql
|
96
|
+
$log.info "bulk insert values size => #{values.size}"
|
97
|
+
@handler.xquery(sql)
|
99
98
|
@handler.close
|
100
99
|
end
|
101
100
|
|
@@ -7,7 +7,18 @@ class MysqlBulkOutputTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def create_driver(conf = CONFIG, tag = 'test')
|
10
|
-
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MysqlBulkOutput, tag).configure(conf)
|
10
|
+
d = Fluent::Test::BufferedOutputTestDriver.new(Fluent::MysqlBulkOutput, tag).configure(conf)
|
11
|
+
d.instance.instance_eval {
|
12
|
+
def client
|
13
|
+
obj = Object.new
|
14
|
+
obj.instance_eval {
|
15
|
+
def xquery(*args); [1]; end
|
16
|
+
def close; true; end
|
17
|
+
}
|
18
|
+
obj
|
19
|
+
end
|
20
|
+
}
|
21
|
+
d
|
11
22
|
end
|
12
23
|
|
13
24
|
def test_configure_error
|
@@ -102,4 +113,45 @@ class MysqlBulkOutputTest < Test::Unit::TestCase
|
|
102
113
|
]
|
103
114
|
end
|
104
115
|
end
|
116
|
+
|
117
|
+
def test_variables
|
118
|
+
d = create_driver %[
|
119
|
+
database test_app_development
|
120
|
+
username root
|
121
|
+
password hogehoge
|
122
|
+
column_names id,user_name,created_at,updated_at
|
123
|
+
table users
|
124
|
+
on_duplicate_key_update true
|
125
|
+
on_duplicate_update_keys user_name,updated_at
|
126
|
+
]
|
127
|
+
|
128
|
+
assert_equal ['id','user_name','created_at','updated_at'], d.instance.key_names
|
129
|
+
assert_equal ['id','user_name','created_at','updated_at'], d.instance.column_names
|
130
|
+
assert_equal " ON DUPLICATE KEY UPDATE user_name = VALUES(user_name),updated_at = VALUES(updated_at)", d.instance.instance_variable_get(:@on_duplicate_key_update_sql)
|
131
|
+
|
132
|
+
d = create_driver %[
|
133
|
+
database test_app_development
|
134
|
+
username root
|
135
|
+
password hogehoge
|
136
|
+
column_names id,user_name,created_at,updated_at
|
137
|
+
table users
|
138
|
+
]
|
139
|
+
|
140
|
+
assert_equal ['id','user_name','created_at','updated_at'], d.instance.key_names
|
141
|
+
assert_equal ['id','user_name','created_at','updated_at'], d.instance.column_names
|
142
|
+
assert_nil d.instance.instance_variable_get(:@on_duplicate_key_update_sql)
|
143
|
+
|
144
|
+
d = create_driver %[
|
145
|
+
database test_app_development
|
146
|
+
username root
|
147
|
+
password hogehoge
|
148
|
+
key_names id,user_name,created_at,updated_at
|
149
|
+
column_names id,user,created_date,updated_date
|
150
|
+
table users
|
151
|
+
]
|
152
|
+
|
153
|
+
assert_equal ['id','user_name','created_at','updated_at'], d.instance.key_names
|
154
|
+
assert_equal ['id','user','created_date','updated_date'], d.instance.column_names
|
155
|
+
assert_nil d.instance.instance_variable_get(:@on_duplicate_key_update_sql)
|
156
|
+
end
|
105
157
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mysql-bulk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Toyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|