embulk-output-mysql 0.7.10 → 0.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/build.gradle +1 -2
- data/classpath/{embulk-output-jdbc-0.7.10.jar → embulk-output-jdbc-0.7.11.jar} +0 -0
- data/classpath/{embulk-output-mysql-0.7.10.jar → embulk-output-mysql-0.7.11.jar} +0 -0
- 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/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
- metadata +31 -17
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e6e129b50f732ddc97a6a9b536be38cd7b9093
|
4
|
+
data.tar.gz: 967e7d6b3e1e7927fdf99b317e084734ba91d3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a346fb0bc27a2eb2678ce3a45104546e27e7b5bd35654ffceb36359cd18a8d75d04a17df828746729cedb98337a3aa5e109fa898b445e787411db2416467d92
|
7
|
+
data.tar.gz: a865c64bbe9aa04e8b7a822f1393817a056ca49e6020e8b90a15a55df62354330af2c46edc53de7f6b08c5326ad2886506e3c4831fddc75abe55948a7172ac3b
|
data/README.md
CHANGED
@@ -120,3 +120,19 @@ out:
|
|
120
120
|
```
|
121
121
|
$ ./gradlew gem
|
122
122
|
```
|
123
|
+
|
124
|
+
Running tests:
|
125
|
+
|
126
|
+
You need to create 'mysql.yml' as follows.
|
127
|
+
```
|
128
|
+
type: mysql
|
129
|
+
host: localhost
|
130
|
+
port: 3306
|
131
|
+
database: database
|
132
|
+
user: user
|
133
|
+
password: pass
|
134
|
+
```
|
135
|
+
|
136
|
+
```
|
137
|
+
$ EMBULK_OUTPUT_MYSQL_TEST_CONFIG=mysql.yml ./gradlew :embulk-output-mysql:check --info
|
138
|
+
```
|
data/build.gradle
CHANGED
@@ -2,6 +2,5 @@ dependencies {
|
|
2
2
|
compile project(':embulk-output-jdbc')
|
3
3
|
compile 'mysql:mysql-connector-java:5.1.34'
|
4
4
|
|
5
|
-
testCompile 'org.embulk:embulk-standards:0.8.
|
6
|
-
testCompile project(':embulk-output-jdbc').sourceSets.test.output
|
5
|
+
testCompile 'org.embulk:embulk-standards:0.8.22'
|
7
6
|
}
|
Binary file
|
Binary file
|
@@ -0,0 +1,136 @@
|
|
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 AfterLoadTest
|
27
|
+
{
|
28
|
+
private static final String BASIC_RESOURCE_PATH = "org/embulk/output/mysql/test/expect/after_load/";
|
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 testInsertAfterLoad() throws Exception
|
56
|
+
{
|
57
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
58
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
59
|
+
|
60
|
+
Path in1 = toPath("test1.csv");
|
61
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_after_load.yml")), in1);
|
62
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_insert_after_load_expected.csv")));
|
63
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testInsertDirectAfterLoad() throws Exception
|
68
|
+
{
|
69
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
70
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
71
|
+
|
72
|
+
Path in1 = toPath("test1.csv");
|
73
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_direct_after_load.yml")), in1);
|
74
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_insert_after_load_expected.csv")));
|
75
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
76
|
+
}
|
77
|
+
|
78
|
+
@Test
|
79
|
+
public void testTruncateInsertAfterLoad() throws Exception
|
80
|
+
{
|
81
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
82
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
83
|
+
|
84
|
+
Path in1 = toPath("test1.csv");
|
85
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_replace_after_load.yml")), in1);
|
86
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_replace_after_load_expected.csv")));
|
87
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void testReplaceAfterLoad() throws Exception
|
92
|
+
{
|
93
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
94
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
95
|
+
|
96
|
+
Path in1 = toPath("test1.csv");
|
97
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_truncate_insert_after_load.yml")), in1);
|
98
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_truncate_insert_after_load_expected.csv")));
|
99
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
100
|
+
}
|
101
|
+
|
102
|
+
@Test
|
103
|
+
public void testMergeAfterLoad() throws Exception
|
104
|
+
{
|
105
|
+
execute("insert into test1 values('A002', 1, 'y')");
|
106
|
+
execute("insert into test1 values('A003', 1, 'y')");
|
107
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
108
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
109
|
+
|
110
|
+
Path in1 = toPath("test1.csv");
|
111
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_after_load.yml")), in1);
|
112
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_merge_after_load_expected.csv")));
|
113
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
114
|
+
}
|
115
|
+
|
116
|
+
@Test
|
117
|
+
public void testMergeDirectAfterLoad() throws Exception
|
118
|
+
{
|
119
|
+
execute("insert into test1 values('A002', 1, 'y')");
|
120
|
+
execute("insert into test1 values('A003', 1, 'y')");
|
121
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
122
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
123
|
+
|
124
|
+
Path in1 = toPath("test1.csv");
|
125
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_direct_after_load.yml")), in1);
|
126
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_merge_after_load_expected.csv")));
|
127
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
128
|
+
}
|
129
|
+
|
130
|
+
private Path toPath(String fileName) throws URISyntaxException
|
131
|
+
{
|
132
|
+
URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
|
133
|
+
return FileSystems.getDefault().getPath(new File(url.toURI()).getAbsolutePath());
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
@@ -0,0 +1,124 @@
|
|
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 BeforeLoadTest
|
27
|
+
{
|
28
|
+
private static final String BASIC_RESOURCE_PATH = "org/embulk/output/mysql/test/expect/before_load/";
|
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 testInsertBeforeLoad() throws Exception
|
56
|
+
{
|
57
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
58
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
59
|
+
|
60
|
+
Path in1 = toPath("test1.csv");
|
61
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_before_load.yml")), in1);
|
62
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_insert_before_load_expected.csv")));
|
63
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testInsertDirectBeforeLoad() throws Exception
|
68
|
+
{
|
69
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
70
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
71
|
+
|
72
|
+
Path in1 = toPath("test1.csv");
|
73
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_direct_before_load.yml")), in1);
|
74
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_insert_before_load_expected.csv")));
|
75
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
76
|
+
}
|
77
|
+
|
78
|
+
@Test
|
79
|
+
public void testTruncateInsertBeforeLoad() throws Exception
|
80
|
+
{
|
81
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
82
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
83
|
+
|
84
|
+
Path in1 = toPath("test1.csv");
|
85
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_truncate_insert_before_load.yml")), in1);
|
86
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_truncate_insert_before_load_expected.csv")));
|
87
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void testMergeBeforeLoad() throws Exception
|
92
|
+
{
|
93
|
+
execute("insert into test1 values('A002', 1, 'y')");
|
94
|
+
execute("insert into test1 values('A003', 1, 'y')");
|
95
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
96
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
97
|
+
|
98
|
+
Path in1 = toPath("test1.csv");
|
99
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_before_load.yml")), in1);
|
100
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_merge_before_load_expected.csv")));
|
101
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
102
|
+
}
|
103
|
+
|
104
|
+
@Test
|
105
|
+
public void testMergeDirectBeforeLoad() throws Exception
|
106
|
+
{
|
107
|
+
execute("insert into test1 values('A002', 1, 'y')");
|
108
|
+
execute("insert into test1 values('A003', 1, 'y')");
|
109
|
+
execute("insert into test1 values('B001', 0, 'z')");
|
110
|
+
execute("insert into test1 values('B002', 9, 'z')");
|
111
|
+
|
112
|
+
Path in1 = toPath("test1.csv");
|
113
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_direct_before_load.yml")), in1);
|
114
|
+
assertThat(selectRecords(embulk, "test1"), is(readResource("test_merge_before_load_expected.csv")));
|
115
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
116
|
+
}
|
117
|
+
|
118
|
+
private Path toPath(String fileName) throws URISyntaxException
|
119
|
+
{
|
120
|
+
URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
|
121
|
+
return FileSystems.getDefault().getPath(new File(url.toURI()).getAbsolutePath());
|
122
|
+
}
|
123
|
+
|
124
|
+
}
|
@@ -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
|
+
}
|