embulk-output-mysql 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/build.gradle +3 -3
  4. data/classpath/embulk-output-jdbc-0.8.0.jar +0 -0
  5. data/classpath/embulk-output-mysql-0.8.0.jar +0 -0
  6. data/default_jdbc_driver/mysql-connector-java-5.1.44.jar +0 -0
  7. data/src/main/java/org/embulk/output/MySQLOutputPlugin.java +56 -16
  8. data/src/main/java/org/embulk/output/MySQLTimeZoneComparison.java +107 -0
  9. data/src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java +14 -5
  10. data/src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java +3 -8
  11. data/src/test/java/org/embulk/output/mysql/AfterLoadTest.java +136 -0
  12. data/src/test/java/org/embulk/output/mysql/BeforeLoadTest.java +124 -0
  13. data/src/test/java/org/embulk/output/mysql/CreateTableTest.java +79 -0
  14. data/src/test/java/org/embulk/output/mysql/MySQLTests.java +69 -0
  15. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/setup.sql +8 -0
  16. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test1.csv +4 -0
  17. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_expected.diff +2 -0
  18. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load.yml +3 -0
  19. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load_expected.csv +5 -0
  20. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_direct_after_load.yml +3 -0
  21. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load.yml +3 -0
  22. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load_expected.csv +5 -0
  23. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_direct_after_load.yml +3 -0
  24. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load.yml +3 -0
  25. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load_expected.csv +3 -0
  26. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load.yml +3 -0
  27. data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load_expected.csv +3 -0
  28. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/setup.sql +8 -0
  29. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test1.csv +4 -0
  30. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_expected.diff +2 -0
  31. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_before_load.yml +3 -0
  32. data/src/test/resources/{mysql/data/test1.csv → org/embulk/output/mysql/test/expect/before_load/test_insert_before_load_expected.csv} +1 -0
  33. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_direct_before_load.yml +3 -0
  34. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load.yml +3 -0
  35. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load_expected.csv +4 -0
  36. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_direct_before_load.yml +3 -0
  37. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load.yml +3 -0
  38. data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load_expected.csv +4 -0
  39. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/setup.sql +1 -0
  40. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test1.csv +4 -0
  41. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint.yml +5 -0
  42. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint_expected.csv +3 -0
  43. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option.yml +5 -0
  44. data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option_expected.csv +3 -0
  45. metadata +40 -18
  46. data/classpath/embulk-output-jdbc-0.7.7.jar +0 -0
  47. data/classpath/embulk-output-mysql-0.7.7.jar +0 -0
  48. data/classpath/mysql-connector-java-5.1.34.jar +0 -0
  49. data/src/test/java/org/embulk/output/mysql/MySQLOutputPluginTest.java +0 -569
  50. data/src/test/resources/mysql/yml/test-insert-after-load.yml +0 -22
  51. data/src/test/resources/mysql/yml/test-insert-before-load.yml +0 -22
  52. data/src/test/resources/mysql/yml/test-insert-direct-after-load.yml +0 -22
  53. data/src/test/resources/mysql/yml/test-insert-direct-before-load.yml +0 -22
  54. data/src/test/resources/mysql/yml/test-merge-after-load.yml +0 -22
  55. data/src/test/resources/mysql/yml/test-merge-before-load.yml +0 -22
  56. data/src/test/resources/mysql/yml/test-merge-direct-after-load.yml +0 -22
  57. data/src/test/resources/mysql/yml/test-merge-direct-before-load.yml +0 -22
  58. data/src/test/resources/mysql/yml/test-replace-after-load.yml +0 -22
  59. data/src/test/resources/mysql/yml/test-truncate-insert-after-load.yml +0 -22
  60. data/src/test/resources/mysql/yml/test-truncate-insert-before-load.yml +0 -22
@@ -0,0 +1,79 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import static org.embulk.output.mysql.MySQLTests.execute;
4
+ import static org.embulk.output.mysql.MySQLTests.selectRecords;
5
+ import static org.hamcrest.Matchers.is;
6
+ import static org.junit.Assert.assertThat;
7
+
8
+ import java.io.File;
9
+ import java.net.URISyntaxException;
10
+ import java.net.URL;
11
+ import java.nio.file.FileSystems;
12
+ import java.nio.file.Path;
13
+
14
+ import org.embulk.config.ConfigDiff;
15
+ import org.embulk.config.ConfigSource;
16
+ import org.embulk.output.MySQLOutputPlugin;
17
+ import org.embulk.spi.OutputPlugin;
18
+ import org.embulk.test.EmbulkTests;
19
+ import org.embulk.test.TestingEmbulk;
20
+ import org.junit.Before;
21
+ import org.junit.Rule;
22
+ import org.junit.Test;
23
+
24
+ import com.google.common.io.Resources;
25
+
26
+ public class CreateTableTest
27
+ {
28
+ private static final String BASIC_RESOURCE_PATH = "org/embulk/output/mysql/test/expect/create_table/";
29
+
30
+ private static ConfigSource loadYamlResource(TestingEmbulk embulk, String fileName)
31
+ {
32
+ return embulk.loadYamlResource(BASIC_RESOURCE_PATH + fileName);
33
+ }
34
+
35
+ private static String readResource(String fileName)
36
+ {
37
+ return EmbulkTests.readResource(BASIC_RESOURCE_PATH + fileName);
38
+ }
39
+
40
+ @Rule
41
+ public TestingEmbulk embulk = TestingEmbulk.builder()
42
+ .registerPlugin(OutputPlugin.class, "mysql", MySQLOutputPlugin.class)
43
+ .build();
44
+
45
+ private ConfigSource baseConfig;
46
+
47
+ @Before
48
+ public void setup()
49
+ {
50
+ baseConfig = MySQLTests.baseConfig();
51
+ execute(readResource("setup.sql")); // setup rows
52
+ }
53
+
54
+ @Test
55
+ public void testTableOption() throws Exception
56
+ {
57
+ Path in1 = toPath("test1.csv");
58
+ TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_table_option.yml")), in1);
59
+ assertThat(selectRecords(embulk, "test1"), is(readResource("test_table_option_expected.csv")));
60
+ //assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
61
+ }
62
+
63
+ @Test
64
+ public void testTableConstraint() throws Exception
65
+ {
66
+ Path in1 = toPath("test1.csv");
67
+ // exception will be thrown without table constraint because auto column must be defined as a key.
68
+ TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_table_constraint.yml")), in1);
69
+ assertThat(selectRecords(embulk, "test1"), is(readResource("test_table_constraint_expected.csv")));
70
+ //assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
71
+ }
72
+
73
+ private Path toPath(String fileName) throws URISyntaxException
74
+ {
75
+ URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
76
+ return FileSystems.getDefault().getPath(new File(url.toURI()).getAbsolutePath());
77
+ }
78
+
79
+ }
@@ -0,0 +1,69 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import static java.util.Locale.ENGLISH;
4
+ import static org.embulk.test.EmbulkTests.readSortedFile;
5
+
6
+ import java.io.IOException;
7
+ import java.nio.file.Files;
8
+ import java.nio.file.Path;
9
+
10
+ import org.embulk.config.ConfigSource;
11
+ import org.embulk.test.EmbulkTests;
12
+ import org.embulk.test.TestingEmbulk;
13
+
14
+ import com.google.common.base.Throwables;
15
+ import com.google.common.collect.ImmutableList;
16
+ import com.google.common.io.ByteStreams;
17
+
18
+ public class MySQLTests
19
+ {
20
+ public static ConfigSource baseConfig()
21
+ {
22
+ return EmbulkTests.config("EMBULK_OUTPUT_MYSQL_TEST_CONFIG");
23
+ }
24
+
25
+ public static void execute(String sql)
26
+ {
27
+ ConfigSource config = baseConfig();
28
+
29
+ ImmutableList.Builder<String> args = ImmutableList.builder();
30
+ args.add("mysql")
31
+ .add("-u")
32
+ .add(config.get(String.class, "user"));
33
+ if (!config.get(String.class, "password").isEmpty()) {
34
+ args.add("-p" + config.get(String.class, "password"));
35
+ }
36
+ args
37
+ .add("-h")
38
+ .add(config.get(String.class, "host"))
39
+ .add("-P")
40
+ .add(config.get(String.class, "port", "3306"))
41
+ .add(config.get(String.class, "database"))
42
+ .add("-e")
43
+ .add(sql);
44
+
45
+ ProcessBuilder pb = new ProcessBuilder(args.build());
46
+ pb.redirectErrorStream(true);
47
+ int code;
48
+ try {
49
+ Process process = pb.start();
50
+ ByteStreams.copy(process.getInputStream(), System.out);
51
+ code = process.waitFor();
52
+ } catch (IOException | InterruptedException ex) {
53
+ throw Throwables.propagate(ex);
54
+ }
55
+ if (code != 0) {
56
+ throw new RuntimeException(String.format(ENGLISH,
57
+ "Command finished with non-zero exit code. Exit code is %d.", code));
58
+ }
59
+ }
60
+
61
+ public static String selectRecords(TestingEmbulk embulk, String tableName) throws IOException
62
+ {
63
+ Path temp = embulk.createTempFile("txt");
64
+ Files.delete(temp);
65
+ // test user needs FILE privilege
66
+ execute("select * from " + tableName + " into outfile '" + temp.toString().replace("\\", "\\\\") + "' fields terminated by ','");
67
+ return readSortedFile(temp);
68
+ }
69
+ }
@@ -0,0 +1,8 @@
1
+ drop table if exists test1;
2
+
3
+ create table test1 (
4
+ id char(4),
5
+ int_item int,
6
+ varchar_item varchar(8),
7
+ primary key (id)
8
+ );
@@ -0,0 +1,4 @@
1
+ id:string,int_item:long,varchar_item:string
2
+ A001,9,a
3
+ A002,0,b
4
+ A003,9,c
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: insert
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,5 @@
1
+ A001,9,x
2
+ A002,0,b
3
+ A003,9,x
4
+ B001,0,z
5
+ B002,9,x
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: insert_direct
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: merge
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,5 @@
1
+ A001,9,x
2
+ A002,0,b
3
+ A003,9,x
4
+ B001,0,z
5
+ B002,9,x
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: merge_direct
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: replace
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: truncate_insert
3
+ after_load: "update test1 set varchar_item = 'x' where int_item = 9"
@@ -0,0 +1,8 @@
1
+ drop table if exists test1;
2
+
3
+ create table test1 (
4
+ id char(4),
5
+ int_item int,
6
+ varchar_item varchar(8),
7
+ primary key (id)
8
+ );
@@ -0,0 +1,4 @@
1
+ id:string,int_item:long,varchar_item:string
2
+ A001,9,a
3
+ A002,0,b
4
+ A003,9,c
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: insert
3
+ before_load: "delete from test1 where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: insert_direct
3
+ before_load: "delete from test1 where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: merge
3
+ before_load: "delete from test1 where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: merge_direct
3
+ before_load: "delete from test1 where int_item = 9"
@@ -0,0 +1,3 @@
1
+ table: test1
2
+ mode: truncate_insert
3
+ before_load: "insert into test1 values('C001', 0, 'x')"
@@ -0,0 +1 @@
1
+ drop table if exists test1;
@@ -0,0 +1,4 @@
1
+ id:long,value:string
2
+ 0,a
3
+ 0,b
4
+ 0,c
@@ -0,0 +1,5 @@
1
+ table: test1
2
+ mode: insert
3
+ create_table_constraint: 'primary key(id)'
4
+ column_options:
5
+ id: {type: 'int auto_increment'}
@@ -0,0 +1,5 @@
1
+ table: test1
2
+ mode: insert
3
+ create_table_option: 'auto_increment=100'
4
+ column_options:
5
+ id: {type: 'int auto_increment primary key'}
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.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -19,27 +19,49 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-output-jdbc-0.7.7.jar
23
- - classpath/embulk-output-mysql-0.7.7.jar
24
- - classpath/mysql-connector-java-5.1.34.jar
22
+ - classpath/embulk-output-jdbc-0.8.0.jar
23
+ - classpath/embulk-output-mysql-0.8.0.jar
24
+ - default_jdbc_driver/mysql-connector-java-5.1.44.jar
25
25
  - lib/embulk/output/mysql.rb
26
26
  - src/main/java/org/embulk/output/MySQLOutputPlugin.java
27
+ - src/main/java/org/embulk/output/MySQLTimeZoneComparison.java
27
28
  - src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java
28
29
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java
29
30
  - 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-before-load.yml
34
- - src/test/resources/mysql/yml/test-insert-direct-after-load.yml
35
- - src/test/resources/mysql/yml/test-insert-direct-before-load.yml
36
- - src/test/resources/mysql/yml/test-merge-after-load.yml
37
- - src/test/resources/mysql/yml/test-merge-before-load.yml
38
- - src/test/resources/mysql/yml/test-merge-direct-after-load.yml
39
- - src/test/resources/mysql/yml/test-merge-direct-before-load.yml
40
- - src/test/resources/mysql/yml/test-replace-after-load.yml
41
- - src/test/resources/mysql/yml/test-truncate-insert-after-load.yml
42
- - src/test/resources/mysql/yml/test-truncate-insert-before-load.yml
31
+ - src/test/java/org/embulk/output/mysql/AfterLoadTest.java
32
+ - src/test/java/org/embulk/output/mysql/BeforeLoadTest.java
33
+ - src/test/java/org/embulk/output/mysql/CreateTableTest.java
34
+ - src/test/java/org/embulk/output/mysql/MySQLTests.java
35
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/setup.sql
36
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test1.csv
37
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_expected.diff
38
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load.yml
39
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load_expected.csv
40
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_direct_after_load.yml
41
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load.yml
42
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load_expected.csv
43
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_direct_after_load.yml
44
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load.yml
45
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load_expected.csv
46
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load.yml
47
+ - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load_expected.csv
48
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/setup.sql
49
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test1.csv
50
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_expected.diff
51
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_before_load.yml
52
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_before_load_expected.csv
53
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_direct_before_load.yml
54
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load.yml
55
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load_expected.csv
56
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_direct_before_load.yml
57
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load.yml
58
+ - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load_expected.csv
59
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/setup.sql
60
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test1.csv
61
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint.yml
62
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint_expected.csv
63
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option.yml
64
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option_expected.csv
43
65
  homepage: https://github.com/embulk/embulk-output-jdbc
44
66
  licenses:
45
67
  - Apache 2.0
Binary file