embulk-output-sqlserver 0.7.10 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/build.gradle +1 -1
- data/classpath/{embulk-output-jdbc-0.7.10.jar → embulk-output-jdbc-0.7.11.jar} +0 -0
- data/classpath/{embulk-output-sqlserver-0.7.10.jar → embulk-output-sqlserver-0.7.11.jar} +0 -0
- data/src/main/java/org/embulk/output/SQLServerOutputPlugin.java +17 -8
- data/src/test/java/org/embulk/output/sqlserver/BasicTest.java +200 -0
- data/src/test/java/org/embulk/output/sqlserver/SQLServerTests.java +80 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/setup.sql +82 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test1.csv +4 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_expected.diff +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_insert.yml +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_insert_create_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_insert_direct.yml +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_insert_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_merge.csv +5 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_merge.yml +2 -0
- data/src/test/resources/{sqlserver/data/test6/test6.csv → org/embulk/output/sqlserver/test/expect/basic/test_merge_expected.csv} +6 -4
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_merge_keys.yml +3 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_merge_rule.yml +3 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_merge_rule_expected.csv +6 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_native_insert_direct.yml +3 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_replace.yml +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_replace_longname.yml +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_string_timestamp.csv +4 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_string_timestamp.yml +5 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_string_timestamp_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_truncate_insert.yml +2 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/basic/test_truncate_insert_expected.csv +3 -0
- metadata +27 -27
- data/src/test/java/org/embulk/output/sqlserver/PreciseTime.java +0 -48
- data/src/test/java/org/embulk/output/sqlserver/SQLServerOutputPluginTest.java +0 -923
- data/src/test/resources/sqlserver/data/test1/test1.csv +0 -3
- data/src/test/resources/sqlserver/data/test2/test2.csv +0 -2
- data/src/test/resources/sqlserver/data/test3/test3.csv +0 -2
- data/src/test/resources/sqlserver/data/test4/test4.csv +0 -2
- data/src/test/resources/sqlserver/data/test5/test5.csv +0 -2
- data/src/test/resources/sqlserver/yml/test-insert-direct.yml +0 -43
- data/src/test/resources/sqlserver/yml/test-insert.yml +0 -43
- data/src/test/resources/sqlserver/yml/test-jtds.yml +0 -43
- data/src/test/resources/sqlserver/yml/test-merge-keys.yml +0 -23
- data/src/test/resources/sqlserver/yml/test-merge-rule.yml +0 -22
- data/src/test/resources/sqlserver/yml/test-merge.yml +0 -21
- data/src/test/resources/sqlserver/yml/test-native-date.yml +0 -26
- data/src/test/resources/sqlserver/yml/test-native-decimal.yml +0 -25
- data/src/test/resources/sqlserver/yml/test-native-integer.yml +0 -24
- data/src/test/resources/sqlserver/yml/test-native-string.yml +0 -25
- data/src/test/resources/sqlserver/yml/test-native.yml +0 -44
- data/src/test/resources/sqlserver/yml/test-replace-long-name.yml +0 -43
- data/src/test/resources/sqlserver/yml/test-replace.yml +0 -43
- data/src/test/resources/sqlserver/yml/test-string-timestamp.yml +0 -46
- data/src/test/resources/sqlserver/yml/test-truncate-insert.yml +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8d8e2c0bbd2a1255d5825697f0c6f2e893d9753
|
4
|
+
data.tar.gz: 14ee14826f9dea6d9d5549e7bdaa41bcb01d8943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913d8c0c5b02f0ef7488c3063b0e022b606774c6c0856d2a78670e2119a5b7708eb88efa1f1e47e4cbe9014ecf448eb0a867bc528d6ef76e67c4f493658a437c
|
7
|
+
data.tar.gz: df036fa9b4a164a18238f56273ba578d962bc1f43d97037e9dc740aa0517fedaf624bef35443631e5df7b8afeb728712aa5d90473e38ac0ed73ec52f546261e0
|
data/README.md
CHANGED
@@ -147,3 +147,19 @@ out:
|
|
147
147
|
```
|
148
148
|
$ ./gradlew gem
|
149
149
|
```
|
150
|
+
|
151
|
+
Running tests:
|
152
|
+
|
153
|
+
You need to put 'sqljdbc41.jar' into 'embulk-output-sqlserver/driver' directory and create 'sqlserver.yml' as follows.
|
154
|
+
```
|
155
|
+
type: sqlserver
|
156
|
+
host: localhost
|
157
|
+
port: 1433
|
158
|
+
database: database
|
159
|
+
user: user
|
160
|
+
password: pass
|
161
|
+
```
|
162
|
+
|
163
|
+
```
|
164
|
+
$ EMBULK_OUTPUT_SQLSERVER_TEST_CONFIG=sqlserver.yml ./gradlew :embulk-output-sqlserver:check --info
|
165
|
+
```
|
data/build.gradle
CHANGED
@@ -2,7 +2,7 @@ dependencies {
|
|
2
2
|
compile project(':embulk-output-jdbc')
|
3
3
|
compile 'net.sourceforge.jtds:jtds:1.3.1'
|
4
4
|
|
5
|
-
testCompile 'org.embulk:embulk-standards:0.8.
|
5
|
+
testCompile 'org.embulk:embulk-standards:0.8.22'
|
6
6
|
testCompile project(':embulk-output-jdbc').sourceSets.test.output
|
7
7
|
testCompile files('driver/sqljdbc41.jar')
|
8
8
|
}
|
Binary file
|
Binary file
|
@@ -28,6 +28,9 @@ import static java.util.Locale.ENGLISH;
|
|
28
28
|
public class SQLServerOutputPlugin
|
29
29
|
extends AbstractJdbcOutputPlugin
|
30
30
|
{
|
31
|
+
// for test
|
32
|
+
public static boolean preferMicrosoftDriver = true;
|
33
|
+
|
31
34
|
private static int DEFAULT_PORT = 1433;
|
32
35
|
|
33
36
|
public interface SQLServerPluginTask
|
@@ -128,20 +131,26 @@ public class SQLServerOutputPlugin
|
|
128
131
|
loadDriverJar(sqlServerTask.getDriverPath().get());
|
129
132
|
try {
|
130
133
|
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
131
|
-
} catch(Exception e) {
|
134
|
+
} catch (Exception e) {
|
132
135
|
throw new ConfigException("Driver set at field 'driver_path' doesn't include Microsoft SQLServerDriver", e);
|
133
136
|
}
|
134
137
|
} else {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
boolean useMicrosoftDriver = false;
|
139
|
+
if (preferMicrosoftDriver) {
|
140
|
+
// prefer Microsoft SQLServerDriver if it is in classpath
|
141
|
+
try {
|
142
|
+
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
143
|
+
useMicrosoftDriver = true;
|
144
|
+
} catch (Exception e) {
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!useMicrosoftDriver) {
|
139
149
|
logger.info("Using jTDS Driver");
|
140
150
|
try {
|
141
151
|
Class.forName("net.sourceforge.jtds.jdbc.Driver");
|
142
|
-
} catch(Exception
|
143
|
-
throw new ConfigException("'driver_path' doesn't set and can't
|
144
|
-
|
152
|
+
} catch (Exception e) {
|
153
|
+
throw new ConfigException("'driver_path' doesn't set and can't find jTDS driver", e);
|
145
154
|
}
|
146
155
|
useJtdsDriver = true;
|
147
156
|
}
|
@@ -0,0 +1,200 @@
|
|
1
|
+
package org.embulk.output.sqlserver;
|
2
|
+
|
3
|
+
import static org.embulk.output.sqlserver.SQLServerTests.execute;
|
4
|
+
import static org.embulk.output.sqlserver.SQLServerTests.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.SQLServerOutputPlugin;
|
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 BasicTest
|
27
|
+
{
|
28
|
+
private static final String BASIC_RESOURCE_PATH = "org/embulk/output/sqlserver/test/expect/basic/";
|
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, "sqlserver", SQLServerOutputPlugin.class)
|
43
|
+
.build();
|
44
|
+
|
45
|
+
private ConfigSource baseConfig;
|
46
|
+
|
47
|
+
@Before
|
48
|
+
public void setup()
|
49
|
+
{
|
50
|
+
baseConfig = SQLServerTests.baseConfig();
|
51
|
+
execute(readResource("setup.sql")); // setup rows
|
52
|
+
}
|
53
|
+
|
54
|
+
@Test
|
55
|
+
public void testInsert() throws Exception
|
56
|
+
{
|
57
|
+
Path in1 = toPath("test1.csv");
|
58
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert.yml")), in1);
|
59
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_expected.csv")));
|
60
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
61
|
+
}
|
62
|
+
|
63
|
+
@Test
|
64
|
+
public void testInsertCreate() throws Exception
|
65
|
+
{
|
66
|
+
execute("DROP TABLE TEST1");
|
67
|
+
|
68
|
+
Path in1 = toPath("test1.csv");
|
69
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert.yml")), in1);
|
70
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_create_expected.csv")));
|
71
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
72
|
+
}
|
73
|
+
|
74
|
+
@Test
|
75
|
+
public void testInsertDirect() throws Exception
|
76
|
+
{
|
77
|
+
Path in1 = toPath("test1.csv");
|
78
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_direct.yml")), in1);
|
79
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_expected.csv")));
|
80
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
81
|
+
}
|
82
|
+
|
83
|
+
@Test
|
84
|
+
public void testInsertDirectCreate() throws Exception
|
85
|
+
{
|
86
|
+
execute("DROP TABLE TEST1");
|
87
|
+
|
88
|
+
Path in1 = toPath("test1.csv");
|
89
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert_direct.yml")), in1);
|
90
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_create_expected.csv")));
|
91
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
92
|
+
}
|
93
|
+
|
94
|
+
@Test
|
95
|
+
public void testTruncateInsert() throws Exception
|
96
|
+
{
|
97
|
+
Path in1 = toPath("test1.csv");
|
98
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_truncate_insert.yml")), in1);
|
99
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_truncate_insert_expected.csv")));
|
100
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
101
|
+
}
|
102
|
+
|
103
|
+
@Test
|
104
|
+
public void testReplace() throws Exception
|
105
|
+
{
|
106
|
+
Path in1 = toPath("test1.csv");
|
107
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_replace.yml")), in1);
|
108
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_create_expected.csv")));
|
109
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
110
|
+
}
|
111
|
+
|
112
|
+
@Test
|
113
|
+
public void testReplaceCreate() throws Exception
|
114
|
+
{
|
115
|
+
execute("DROP TABLE TEST1");
|
116
|
+
|
117
|
+
Path in1 = toPath("test1.csv");
|
118
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_replace.yml")), in1);
|
119
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_create_expected.csv")));
|
120
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
121
|
+
}
|
122
|
+
|
123
|
+
@Test
|
124
|
+
public void testReplaceLongName() throws Exception
|
125
|
+
{
|
126
|
+
String tableName = "TEST___A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789";
|
127
|
+
assertThat(tableName.length(), is(127));
|
128
|
+
|
129
|
+
Path in1 = toPath("test1.csv");
|
130
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_replace_longname.yml")), in1);
|
131
|
+
assertThat(selectRecords(embulk, tableName), is(readResource("test_insert_create_expected.csv")));
|
132
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
133
|
+
}
|
134
|
+
|
135
|
+
@Test
|
136
|
+
public void testMerge() throws Exception
|
137
|
+
{
|
138
|
+
Path in1 = toPath("test_merge.csv");
|
139
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge.yml")), in1);
|
140
|
+
assertThat(selectRecords(embulk, "TEST_MERGE1"), is(readResource("test_merge_expected.csv")));
|
141
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
142
|
+
}
|
143
|
+
|
144
|
+
@Test
|
145
|
+
public void testMergeWithKeys() throws Exception
|
146
|
+
{
|
147
|
+
Path in1 = toPath("test_merge.csv");
|
148
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_keys.yml")), in1);
|
149
|
+
assertThat(selectRecords(embulk, "TEST_MERGE2"), is(readResource("test_merge_expected.csv")));
|
150
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
151
|
+
}
|
152
|
+
|
153
|
+
@Test
|
154
|
+
public void testMergeWithRule() throws Exception
|
155
|
+
{
|
156
|
+
Path in1 = toPath("test_merge.csv");
|
157
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_merge_rule.yml")), in1);
|
158
|
+
assertThat(selectRecords(embulk, "TEST_MERGE1"), is(readResource("test_merge_rule_expected.csv")));
|
159
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
160
|
+
}
|
161
|
+
|
162
|
+
@Test
|
163
|
+
public void testNativeInsertDirect() throws Exception
|
164
|
+
{
|
165
|
+
Path in1 = toPath("test1.csv");
|
166
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_native_insert_direct.yml")), in1);
|
167
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_expected.csv")));
|
168
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
169
|
+
}
|
170
|
+
|
171
|
+
@Test
|
172
|
+
public void testStringToTimestamp() throws Exception
|
173
|
+
{
|
174
|
+
Path in1 = toPath("test_string_timestamp.csv");
|
175
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_string_timestamp.yml")), in1);
|
176
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_string_timestamp_expected.csv")));
|
177
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
178
|
+
}
|
179
|
+
|
180
|
+
@Test
|
181
|
+
public void testJtds() throws Exception
|
182
|
+
{
|
183
|
+
SQLServerOutputPlugin.preferMicrosoftDriver = false;
|
184
|
+
try {
|
185
|
+
Path in1 = toPath("test1.csv");
|
186
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_insert.yml")), in1);
|
187
|
+
assertThat(selectRecords(embulk, "TEST1"), is(readResource("test_insert_expected.csv")));
|
188
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
189
|
+
} finally {
|
190
|
+
SQLServerOutputPlugin.preferMicrosoftDriver = true;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
private Path toPath(String fileName) throws URISyntaxException
|
195
|
+
{
|
196
|
+
URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
|
197
|
+
return FileSystems.getDefault().getPath(new File(url.toURI()).getAbsolutePath());
|
198
|
+
}
|
199
|
+
|
200
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
package org.embulk.output.sqlserver;
|
2
|
+
|
3
|
+
import static java.util.Locale.ENGLISH;
|
4
|
+
|
5
|
+
import java.io.IOException;
|
6
|
+
import java.nio.charset.Charset;
|
7
|
+
import java.nio.file.Files;
|
8
|
+
import java.nio.file.Path;
|
9
|
+
import java.util.Collections;
|
10
|
+
import java.util.List;
|
11
|
+
|
12
|
+
import org.embulk.config.ConfigSource;
|
13
|
+
import org.embulk.test.EmbulkTests;
|
14
|
+
import org.embulk.test.TestingEmbulk;
|
15
|
+
|
16
|
+
import com.google.common.base.Throwables;
|
17
|
+
import com.google.common.collect.ImmutableList;
|
18
|
+
import com.google.common.io.ByteStreams;
|
19
|
+
|
20
|
+
public class SQLServerTests
|
21
|
+
{
|
22
|
+
public static ConfigSource baseConfig()
|
23
|
+
{
|
24
|
+
return EmbulkTests.config("EMBULK_OUTPUT_SQLSERVER_TEST_CONFIG");
|
25
|
+
}
|
26
|
+
|
27
|
+
public static void execute(String sql, String... options)
|
28
|
+
{
|
29
|
+
ConfigSource config = baseConfig();
|
30
|
+
|
31
|
+
ImmutableList.Builder<String> args = ImmutableList.builder();
|
32
|
+
args.add("sqlcmd")
|
33
|
+
.add("-U")
|
34
|
+
.add(config.get(String.class, "user"))
|
35
|
+
.add("-P")
|
36
|
+
.add(config.get(String.class, "password"))
|
37
|
+
.add("-H")
|
38
|
+
.add(config.get(String.class, "host"))
|
39
|
+
.add("-d")
|
40
|
+
.add(config.get(String.class, "database"))
|
41
|
+
.add("-Q")
|
42
|
+
.add(sql);
|
43
|
+
for (String option : options) {
|
44
|
+
args.add(option);
|
45
|
+
}
|
46
|
+
|
47
|
+
ProcessBuilder pb = new ProcessBuilder(args.build());
|
48
|
+
pb.redirectErrorStream(true);
|
49
|
+
int code;
|
50
|
+
try {
|
51
|
+
Process process = pb.start();
|
52
|
+
ByteStreams.copy(process.getInputStream(), System.out);
|
53
|
+
code = process.waitFor();
|
54
|
+
} catch (IOException | InterruptedException ex) {
|
55
|
+
throw Throwables.propagate(ex);
|
56
|
+
}
|
57
|
+
if (code != 0) {
|
58
|
+
throw new RuntimeException(String.format(ENGLISH,
|
59
|
+
"Command finished with non-zero exit code. Exit code is %d.", code));
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
public static String selectRecords(TestingEmbulk embulk, String tableName) throws IOException
|
64
|
+
{
|
65
|
+
Path temp = embulk.createTempFile("txt");
|
66
|
+
Files.delete(temp);
|
67
|
+
|
68
|
+
// should not use UTF8 because of BOM
|
69
|
+
execute("SET NOCOUNT ON; SELECT * FROM " + tableName, "-h", "-1", "-s", ",", "-W", "-f", "932", "-o", temp.toString());
|
70
|
+
|
71
|
+
List<String> lines = Files.readAllLines(temp, Charset.forName("MS932"));
|
72
|
+
Collections.sort(lines);
|
73
|
+
StringBuilder sb = new StringBuilder();
|
74
|
+
for (String line : lines) {
|
75
|
+
sb.append(line);
|
76
|
+
sb.append("\n");
|
77
|
+
}
|
78
|
+
return sb.toString();
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
DROP TABLE TEST1
|
2
|
+
CREATE TABLE TEST1 (
|
3
|
+
ID CHAR(4),
|
4
|
+
TINYINT_ITEM TINYINT,
|
5
|
+
SMALLINT_ITEM SMALLINT,
|
6
|
+
INT_ITEM INT,
|
7
|
+
BIGINT_ITEM BIGINT,
|
8
|
+
BIT_ITEM BIT,
|
9
|
+
DECIMAL_ITEM DECIMAL(12,2),
|
10
|
+
NUMERIC_ITEM NUMERIC(5,3),
|
11
|
+
SMALLMONEY_ITEM SMALLMONEY,
|
12
|
+
MONEY_ITEM MONEY,
|
13
|
+
REAL_ITEM REAL,
|
14
|
+
FLOAT_ITEM FLOAT,
|
15
|
+
CHAR_ITEM CHAR(4),
|
16
|
+
VARCHAR_ITEM VARCHAR(8),
|
17
|
+
TEXT_ITEM TEXT,
|
18
|
+
NCHAR_ITEM NCHAR(4),
|
19
|
+
NVARCHAR_ITEM NVARCHAR(8),
|
20
|
+
NTEXT_ITEM NTEXT,
|
21
|
+
DATE_ITEM DATE,
|
22
|
+
DATETIME_ITEM DATETIME,
|
23
|
+
DATETIME2_ITEM DATETIME2,
|
24
|
+
DATETIME2_2_ITEM DATETIME2(2),
|
25
|
+
SMALLDATETIME_ITEM SMALLDATETIME,
|
26
|
+
TIME_ITEM TIME,
|
27
|
+
TIME_2_ITEM TIME(2),
|
28
|
+
PRIMARY KEY (ID)
|
29
|
+
);
|
30
|
+
INSERT INTO TEST1(ID) VALUES('9999');
|
31
|
+
|
32
|
+
DROP TABLE TEST___A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789
|
33
|
+
CREATE TABLE TEST___A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789 (
|
34
|
+
ID CHAR(4),
|
35
|
+
TINYINT_ITEM TINYINT,
|
36
|
+
SMALLINT_ITEM SMALLINT,
|
37
|
+
INT_ITEM INT,
|
38
|
+
BIGINT_ITEM BIGINT,
|
39
|
+
BIT_ITEM BIT,
|
40
|
+
DECIMAL_ITEM DECIMAL(12,2),
|
41
|
+
NUMERIC_ITEM NUMERIC(5,3),
|
42
|
+
SMALLMONEY_ITEM SMALLMONEY,
|
43
|
+
MONEY_ITEM MONEY,
|
44
|
+
REAL_ITEM REAL,
|
45
|
+
FLOAT_ITEM FLOAT,
|
46
|
+
CHAR_ITEM CHAR(4),
|
47
|
+
VARCHAR_ITEM VARCHAR(8),
|
48
|
+
TEXT_ITEM TEXT,
|
49
|
+
NCHAR_ITEM NCHAR(4),
|
50
|
+
NVARCHAR_ITEM NVARCHAR(8),
|
51
|
+
NTEXT_ITEM NTEXT,
|
52
|
+
DATE_ITEM DATE,
|
53
|
+
DATETIME_ITEM DATETIME,
|
54
|
+
DATETIME2_ITEM DATETIME2,
|
55
|
+
DATETIME2_2_ITEM DATETIME2(2),
|
56
|
+
SMALLDATETIME_ITEM SMALLDATETIME,
|
57
|
+
TIME_ITEM TIME,
|
58
|
+
TIME_2_ITEM TIME(2),
|
59
|
+
PRIMARY KEY (ID)
|
60
|
+
);
|
61
|
+
INSERT INTO TEST___A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789(ID) VALUES('9999');
|
62
|
+
|
63
|
+
DROP TABLE TEST_MERGE1;
|
64
|
+
CREATE TABLE TEST_MERGE1 (
|
65
|
+
ITEM1 INT,
|
66
|
+
ITEM2 INT,
|
67
|
+
ITEM3 VARCHAR(4),
|
68
|
+
PRIMARY KEY(ITEM1, ITEM2)
|
69
|
+
);
|
70
|
+
INSERT INTO TEST_MERGE1 VALUES(10, 20, 'A');
|
71
|
+
INSERT INTO TEST_MERGE1 VALUES(10, 21, 'B');
|
72
|
+
INSERT INTO TEST_MERGE1 VALUES(11, 20, 'C');
|
73
|
+
|
74
|
+
DROP TABLE TEST_MERGE2;
|
75
|
+
CREATE TABLE TEST_MERGE2 (
|
76
|
+
ITEM1 INT,
|
77
|
+
ITEM2 INT,
|
78
|
+
ITEM3 VARCHAR(4)
|
79
|
+
);
|
80
|
+
INSERT INTO TEST_MERGE2 VALUES(10, 20, 'A');
|
81
|
+
INSERT INTO TEST_MERGE2 VALUES(10, 21, 'B');
|
82
|
+
INSERT INTO TEST_MERGE2 VALUES(11, 20, 'C');
|