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.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/build.gradle +3 -3
- data/classpath/embulk-output-jdbc-0.8.0.jar +0 -0
- data/classpath/embulk-output-mysql-0.8.0.jar +0 -0
- data/default_jdbc_driver/mysql-connector-java-5.1.44.jar +0 -0
- data/src/main/java/org/embulk/output/MySQLOutputPlugin.java +56 -16
- data/src/main/java/org/embulk/output/MySQLTimeZoneComparison.java +107 -0
- data/src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java +14 -5
- data/src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java +3 -8
- data/src/test/java/org/embulk/output/mysql/AfterLoadTest.java +136 -0
- data/src/test/java/org/embulk/output/mysql/BeforeLoadTest.java +124 -0
- data/src/test/java/org/embulk/output/mysql/CreateTableTest.java +79 -0
- data/src/test/java/org/embulk/output/mysql/MySQLTests.java +69 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/setup.sql +8 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test1.csv +4 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_expected.diff +2 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_after_load_expected.csv +5 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_insert_direct_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_after_load_expected.csv +5 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_merge_direct_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_replace_after_load_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/after_load/test_truncate_insert_after_load_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/setup.sql +8 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test1.csv +4 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_expected.diff +2 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_before_load.yml +3 -0
- data/src/test/resources/{mysql/data/test1.csv → org/embulk/output/mysql/test/expect/before_load/test_insert_before_load_expected.csv} +1 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_insert_direct_before_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_before_load_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_direct_before_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load.yml +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/setup.sql +1 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test1.csv +4 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint.yml +5 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option.yml +5 -0
- data/src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option_expected.csv +3 -0
- metadata +40 -18
- data/classpath/embulk-output-jdbc-0.7.7.jar +0 -0
- data/classpath/embulk-output-mysql-0.7.7.jar +0 -0
- data/classpath/mysql-connector-java-5.1.34.jar +0 -0
- data/src/test/java/org/embulk/output/mysql/MySQLOutputPluginTest.java +0 -569
- data/src/test/resources/mysql/yml/test-insert-after-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-insert-before-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-insert-direct-after-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-insert-direct-before-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-merge-after-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-merge-before-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-merge-direct-after-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-merge-direct-before-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-replace-after-load.yml +0 -22
- data/src/test/resources/mysql/yml/test-truncate-insert-after-load.yml +0 -22
- 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 @@
|
|
1
|
+
drop table if exists test1;
|
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.
|
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-
|
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.
|
23
|
-
- classpath/embulk-output-mysql-0.
|
24
|
-
-
|
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/
|
31
|
-
- src/test/
|
32
|
-
- src/test/
|
33
|
-
- src/test/
|
34
|
-
- src/test/resources/mysql/
|
35
|
-
- src/test/resources/mysql/
|
36
|
-
- src/test/resources/mysql/
|
37
|
-
- src/test/resources/mysql/
|
38
|
-
- src/test/resources/mysql/
|
39
|
-
- src/test/resources/mysql/
|
40
|
-
- src/test/resources/mysql/
|
41
|
-
- src/test/resources/mysql/
|
42
|
-
- src/test/resources/mysql/
|
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
|
Binary file
|
Binary file
|