embulk-output-mysql 0.7.0 → 0.7.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: bedcc590df0bc10158116c37710c92cf6f737ce6
4
- data.tar.gz: 6ce3d054a7a9e875238fb554b389f2dc29ef790b
3
+ metadata.gz: 9830d9379f4a4e6e2db01c7048a651b8db696fe2
4
+ data.tar.gz: ce2688a78d31c9e8b417da61ed4e7e4019b289ec
5
5
  SHA512:
6
- metadata.gz: 11418af4cf4d768877c63ae51f2aa66aff48895d3e7ffb51a94d2359375b96deb1e8e78055b7f099a2dffbdc00dced37c43ada67219620289255dc7cc7ed5d76
7
- data.tar.gz: 8653fa077f225e7f32ace989c48dec9a6b36b07249fb93f8982688752a236a0e72d7b31dab3b76eaaf10441c262be4df8061c8271d7ce4e06a258e08011dc1e6
6
+ metadata.gz: 704b948e549ee8a5376558b99688da68742e1c098bb983eb5c6a30e73f4aa5050d15cac526156b1f4172108f185456b6b2bae73cac6817c12aafb5b1cd9b924a
7
+ data.tar.gz: 8329a028727fc4dab736663291c83ae511396cb4c85b282983d1584ffa94048b7f44fa05a51e0b113f2fcdfee489453cbc98e9892177962d008920a7b05061c5
data/README.md CHANGED
@@ -29,6 +29,7 @@ MySQL output plugin for Embulk loads records to MySQL.
29
29
  - **value_type**: This plugin converts input column type (embulk type) into a database type to build a INSERT statement. This value_type option controls the type of the value in a INSERT statement. (string, default: depends on the sql type of the column. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `json`, `null`, `pass`)
30
30
  - **timestamp_format**: If input column type (embulk type) is timestamp and value_type is `string` or `nstring`, this plugin needs to format the timestamp value into a string. This timestamp_format option is used to control the format of the timestamp. (string, default: `%Y-%m-%d %H:%M:%S.%6N`)
31
31
  - **timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp value into a SQL string. In this cases, this timezone option is used to control the timezone. (string, value of default_timezone option is used by default)
32
+ - **after_load**: if set, this SQL will be executed after loading all records.
32
33
 
33
34
  ### Modes
34
35
 
@@ -1,7 +1,7 @@
1
1
  dependencies {
2
2
  compile project(':embulk-output-jdbc')
3
-
4
3
  compile 'mysql:mysql-connector-java:5.1.34'
5
4
 
5
+ testCompile 'org.embulk:embulk-standards:0.8.8'
6
6
  testCompile project(':embulk-output-jdbc').sourceSets.test.output
7
7
  }
@@ -0,0 +1,340 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import static java.util.Locale.ENGLISH;
4
+ import static org.junit.Assert.assertEquals;
5
+
6
+ import java.sql.Connection;
7
+ import java.sql.DriverManager;
8
+ import java.sql.SQLException;
9
+ import java.util.Iterator;
10
+ import java.util.List;
11
+
12
+ import org.embulk.output.AbstractJdbcOutputPluginTest;
13
+ import org.embulk.output.MySQLOutputPlugin;
14
+ import org.embulk.spi.OutputPlugin;
15
+ import org.junit.Test;
16
+
17
+
18
+ public class MySQLOutputPluginTest extends AbstractJdbcOutputPluginTest
19
+ {
20
+ @Override
21
+ protected void prepare() throws SQLException
22
+ {
23
+ tester.addPlugin(OutputPlugin.class, "mysql", MySQLOutputPlugin.class);
24
+
25
+ try {
26
+ connect();
27
+ } catch (SQLException e) {
28
+ System.err.println(e);
29
+ System.err.println(String.format(ENGLISH, "Warning: prepare a schema on MySQL (server = %s, port = %d, database = %s, user = %s, password = %s).",
30
+ getHost(), getPort(), getDatabase(), getUser(), getPassword()));
31
+ return;
32
+ }
33
+
34
+ enabled = true;
35
+ }
36
+
37
+ @Test
38
+ public void testInsertDirectAfterLoad() throws Exception
39
+ {
40
+ if (!enabled) {
41
+ return;
42
+ }
43
+
44
+ String table = "test1";
45
+
46
+ dropTable(table);
47
+ createTable(table);
48
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
49
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
50
+
51
+ test("/mysql/yml/test-insert-direct-after-load.yml");
52
+
53
+ List<List<Object>> rows = select(table);
54
+ assertEquals(5, rows.size());
55
+ Iterator<List<Object>> i1 = rows.iterator();
56
+ {
57
+ Iterator<Object> i2 = i1.next().iterator();
58
+ assertEquals("A001", i2.next());
59
+ assertEquals(9, i2.next());
60
+ assertEquals("x", i2.next());
61
+ }
62
+ {
63
+ Iterator<Object> i2 = i1.next().iterator();
64
+ assertEquals("A002", i2.next());
65
+ assertEquals(0, i2.next());
66
+ assertEquals("b", i2.next());
67
+ }
68
+ {
69
+ Iterator<Object> i2 = i1.next().iterator();
70
+ assertEquals("A003", i2.next());
71
+ assertEquals(9, i2.next());
72
+ assertEquals("x", i2.next());
73
+ }
74
+ {
75
+ Iterator<Object> i2 = i1.next().iterator();
76
+ assertEquals("B001", i2.next());
77
+ assertEquals(0, i2.next());
78
+ assertEquals("z", i2.next());
79
+ }
80
+ {
81
+ Iterator<Object> i2 = i1.next().iterator();
82
+ assertEquals("B002", i2.next());
83
+ assertEquals(9, i2.next());
84
+ assertEquals("x", i2.next());
85
+ }
86
+ }
87
+
88
+ @Test
89
+ public void testInsertAfterLoad() throws Exception
90
+ {
91
+ if (!enabled) {
92
+ return;
93
+ }
94
+
95
+ String table = "test1";
96
+
97
+ dropTable(table);
98
+ createTable(table);
99
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
100
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
101
+
102
+ test("/mysql/yml/test-insert-after-load.yml");
103
+
104
+ List<List<Object>> rows = select(table);
105
+ assertEquals(5, rows.size());
106
+ Iterator<List<Object>> i1 = rows.iterator();
107
+ {
108
+ Iterator<Object> i2 = i1.next().iterator();
109
+ assertEquals("A001", i2.next());
110
+ assertEquals(9, i2.next());
111
+ assertEquals("x", i2.next());
112
+ }
113
+ {
114
+ Iterator<Object> i2 = i1.next().iterator();
115
+ assertEquals("A002", i2.next());
116
+ assertEquals(0, i2.next());
117
+ assertEquals("b", i2.next());
118
+ }
119
+ {
120
+ Iterator<Object> i2 = i1.next().iterator();
121
+ assertEquals("A003", i2.next());
122
+ assertEquals(9, i2.next());
123
+ assertEquals("x", i2.next());
124
+ }
125
+ {
126
+ Iterator<Object> i2 = i1.next().iterator();
127
+ assertEquals("B001", i2.next());
128
+ assertEquals(0, i2.next());
129
+ assertEquals("z", i2.next());
130
+ }
131
+ {
132
+ Iterator<Object> i2 = i1.next().iterator();
133
+ assertEquals("B002", i2.next());
134
+ assertEquals(9, i2.next());
135
+ assertEquals("x", i2.next());
136
+ }
137
+ }
138
+
139
+ @Test
140
+ public void testTruncateInsertAfterLoad() throws Exception
141
+ {
142
+ if (!enabled) {
143
+ return;
144
+ }
145
+
146
+ String table = "test1";
147
+
148
+ dropTable(table);
149
+ createTable(table);
150
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
151
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
152
+
153
+ test("/mysql/yml/test-truncate-insert-after-load.yml");
154
+
155
+ List<List<Object>> rows = select(table);
156
+ assertEquals(3, rows.size());
157
+ Iterator<List<Object>> i1 = rows.iterator();
158
+ {
159
+ Iterator<Object> i2 = i1.next().iterator();
160
+ assertEquals("A001", i2.next());
161
+ assertEquals(9, i2.next());
162
+ assertEquals("x", i2.next());
163
+ }
164
+ {
165
+ Iterator<Object> i2 = i1.next().iterator();
166
+ assertEquals("A002", i2.next());
167
+ assertEquals(0, i2.next());
168
+ assertEquals("b", i2.next());
169
+ }
170
+ {
171
+ Iterator<Object> i2 = i1.next().iterator();
172
+ assertEquals("A003", i2.next());
173
+ assertEquals(9, i2.next());
174
+ assertEquals("x", i2.next());
175
+ }
176
+ }
177
+
178
+ @Test
179
+ public void testReplaceAfterLoad() throws Exception
180
+ {
181
+ if (!enabled) {
182
+ return;
183
+ }
184
+
185
+ String table = "test1";
186
+
187
+ dropTable(table);
188
+ createTable(table);
189
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
190
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
191
+
192
+ test("/mysql/yml/test-replace-after-load.yml");
193
+
194
+ List<List<Object>> rows = select(table);
195
+ assertEquals(3, rows.size());
196
+ Iterator<List<Object>> i1 = rows.iterator();
197
+ {
198
+ Iterator<Object> i2 = i1.next().iterator();
199
+ assertEquals("A001", i2.next());
200
+ assertEquals(9L, i2.next());
201
+ assertEquals("x", i2.next());
202
+ }
203
+ {
204
+ Iterator<Object> i2 = i1.next().iterator();
205
+ assertEquals("A002", i2.next());
206
+ assertEquals(0L, i2.next());
207
+ assertEquals("b", i2.next());
208
+ }
209
+ {
210
+ Iterator<Object> i2 = i1.next().iterator();
211
+ assertEquals("A003", i2.next());
212
+ assertEquals(9L, i2.next());
213
+ assertEquals("x", i2.next());
214
+ }
215
+ }
216
+
217
+ @Test
218
+ public void testMergeDirectAfterLoad() throws Exception
219
+ {
220
+ if (!enabled) {
221
+ return;
222
+ }
223
+
224
+ String table = "test1";
225
+
226
+ dropTable(table);
227
+ createTable(table);
228
+ executeSQL(String.format("INSERT INTO %s VALUES('A002', 1, 'y')", table));
229
+ executeSQL(String.format("INSERT INTO %s VALUES('A003', 1, 'y')", table));
230
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
231
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
232
+
233
+ test("/mysql/yml/test-merge-direct-after-load.yml");
234
+
235
+ List<List<Object>> rows = select(table);
236
+ assertEquals(5, rows.size());
237
+ Iterator<List<Object>> i1 = rows.iterator();
238
+ {
239
+ Iterator<Object> i2 = i1.next().iterator();
240
+ assertEquals("A001", i2.next());
241
+ assertEquals(9, i2.next());
242
+ assertEquals("x", i2.next());
243
+ }
244
+ {
245
+ Iterator<Object> i2 = i1.next().iterator();
246
+ assertEquals("A002", i2.next());
247
+ assertEquals(0, i2.next());
248
+ assertEquals("b", i2.next());
249
+ }
250
+ {
251
+ Iterator<Object> i2 = i1.next().iterator();
252
+ assertEquals("A003", i2.next());
253
+ assertEquals(9, i2.next());
254
+ assertEquals("x", i2.next());
255
+ }
256
+ {
257
+ Iterator<Object> i2 = i1.next().iterator();
258
+ assertEquals("B001", i2.next());
259
+ assertEquals(0, i2.next());
260
+ assertEquals("z", i2.next());
261
+ }
262
+ {
263
+ Iterator<Object> i2 = i1.next().iterator();
264
+ assertEquals("B002", i2.next());
265
+ assertEquals(9, i2.next());
266
+ assertEquals("x", i2.next());
267
+ }
268
+ }
269
+
270
+ @Test
271
+ public void testMergeAfterLoad() throws Exception
272
+ {
273
+ if (!enabled) {
274
+ return;
275
+ }
276
+
277
+ String table = "test1";
278
+
279
+ dropTable(table);
280
+ createTable(table);
281
+ executeSQL(String.format("INSERT INTO %s VALUES('A002', 1, 'y')", table));
282
+ executeSQL(String.format("INSERT INTO %s VALUES('A003', 1, 'y')", table));
283
+ executeSQL(String.format("INSERT INTO %s VALUES('B001', 0, 'z')", table));
284
+ executeSQL(String.format("INSERT INTO %s VALUES('B002', 9, 'z')", table));
285
+
286
+ test("/mysql/yml/test-merge-after-load.yml");
287
+
288
+ List<List<Object>> rows = select(table);
289
+ assertEquals(5, rows.size());
290
+ Iterator<List<Object>> i1 = rows.iterator();
291
+ {
292
+ Iterator<Object> i2 = i1.next().iterator();
293
+ assertEquals("A001", i2.next());
294
+ assertEquals(9, i2.next());
295
+ assertEquals("x", i2.next());
296
+ }
297
+ {
298
+ Iterator<Object> i2 = i1.next().iterator();
299
+ assertEquals("A002", i2.next());
300
+ assertEquals(0, i2.next());
301
+ assertEquals("b", i2.next());
302
+ }
303
+ {
304
+ Iterator<Object> i2 = i1.next().iterator();
305
+ assertEquals("A003", i2.next());
306
+ assertEquals(9, i2.next());
307
+ assertEquals("x", i2.next());
308
+ }
309
+ {
310
+ Iterator<Object> i2 = i1.next().iterator();
311
+ assertEquals("B001", i2.next());
312
+ assertEquals(0, i2.next());
313
+ assertEquals("z", i2.next());
314
+ }
315
+ {
316
+ Iterator<Object> i2 = i1.next().iterator();
317
+ assertEquals("B002", i2.next());
318
+ assertEquals(9, i2.next());
319
+ assertEquals("x", i2.next());
320
+ }
321
+ }
322
+
323
+ private void createTable(String table) throws SQLException
324
+ {
325
+ String sql = String.format("create table %s ("
326
+ + "id char(4),"
327
+ + "int_item int,"
328
+ + "varchar_item varchar(8),"
329
+ + "primary key (id))", table);
330
+ executeSQL(sql);
331
+ }
332
+
333
+ @Override
334
+ protected Connection connect() throws SQLException
335
+ {
336
+ return DriverManager.getConnection(String.format(ENGLISH, "jdbc:mysql://%s:%d/%s", getHost(), getPort(), getDatabase()),
337
+ getUser(), getPassword());
338
+ }
339
+
340
+ }
@@ -0,0 +1,3 @@
1
+ A001,9,a
2
+ A002,0,b
3
+ A003,9,c
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: insert
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: insert_direct
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: merge
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: merge_direct
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: replace
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,22 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/mysql/data/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: int_item, type: long}
13
+ - {name: varchar_item, type: string}
14
+ out:
15
+ type: mysql
16
+ host: #host#
17
+ database: #database#
18
+ user: #user#
19
+ password: #password#
20
+ table: test1
21
+ mode: truncate_insert
22
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2016-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -19,14 +19,22 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-output-jdbc-0.7.0.jar
23
- - classpath/embulk-output-mysql-0.7.0.jar
22
+ - classpath/embulk-output-jdbc-0.7.1.jar
23
+ - classpath/embulk-output-mysql-0.7.1.jar
24
24
  - classpath/mysql-connector-java-5.1.34.jar
25
25
  - lib/embulk/output/mysql.rb
26
26
  - src/main/java/org/embulk/output/MySQLOutputPlugin.java
27
27
  - src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java
28
28
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java
29
29
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java
30
+ - src/test/java/org/embulk/output/mysql/MySQLOutputPluginTest.java
31
+ - src/test/resources/mysql/data/test1.csv
32
+ - src/test/resources/mysql/yml/test-insert-after-load.yml
33
+ - src/test/resources/mysql/yml/test-insert-direct-after-load.yml
34
+ - src/test/resources/mysql/yml/test-merge-after-load.yml
35
+ - src/test/resources/mysql/yml/test-merge-direct-after-load.yml
36
+ - src/test/resources/mysql/yml/test-replace-after-load.yml
37
+ - src/test/resources/mysql/yml/test-truncate-insert-after-load.yml
30
38
  homepage: https://github.com/embulk/embulk-output-jdbc
31
39
  licenses:
32
40
  - Apache 2.0