embulk-output-sqlserver 0.8.0 → 0.8.1
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 +5 -5
- data/classpath/{embulk-output-jdbc-0.8.0.jar → embulk-output-jdbc-0.8.1.jar} +0 -0
- data/classpath/{embulk-output-sqlserver-0.8.0.jar → embulk-output-sqlserver-0.8.1.jar} +0 -0
- data/src/main/java/org/embulk/output/sqlserver/nativeclient/NativeClient.java +2 -0
- data/src/main/java/org/embulk/output/sqlserver/nativeclient/NativeClientWrapper.java +11 -1
- data/src/test/java/org/embulk/output/sqlserver/NativeTest.java +60 -1
- data/src/test/java/org/embulk/output/sqlserver/SQLServerTests.java +18 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/native/setup.sql +9 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_huge.csv +1 -0
- data/src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_huge.yml +3 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64f02cdd0fc14b4644e8dfc1dbdce80a286b80ee
|
4
|
+
data.tar.gz: f286424dbcbb308fc98ff2996ecaab4c32f3bdf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e40b2bf9a2ca5e076cb3f2054bebb39fded85da86196a9627fac8870adc0ff64e8ec90f5d23d1685a9319f0a535b51c02ef4b13784bbd7747c4e93894fb82590
|
7
|
+
data.tar.gz: 5379f7fc7836540a50544d7e1c905346bc1fa2d84a737dd3ef7e1ff5fe2779e886514dd64ccee92645571b9868b84eb4a77b45ffcc9e90c5db6e4352ce906a07
|
data/README.md
CHANGED
@@ -26,12 +26,12 @@ embulk "-J-Djava.library.path=C:\drivers" run input-sqlserver.yml
|
|
26
26
|
- **temp_schema**: schema name for intermediate tables. by default, intermediate tables will be created in the same schema as destination table. (string, optional)
|
27
27
|
- **url**: URL of the JDBC connection (string, optional)
|
28
28
|
- **table**: destination table name (string, required)
|
29
|
-
- **create_table_constraint
|
30
|
-
- **create_table_option
|
29
|
+
- **create_table_constraint**: table constraint added to `CREATE TABLE` statement, like `CREATE TABLE <table_name> (<column1> <type1>, <column2> <type2>, ..., <create_table_constraint>) <create_table_option>`.
|
30
|
+
- **create_table_option**: table option added to `CREATE TABLE` statement, like `CREATE TABLE <table_name> (<column1> <type1>, <column2> <type2>, ..., <create_table_constraint>) <create_table_option>`.
|
31
31
|
- **options**: extra connection properties (hash, default: {})
|
32
|
-
- **retry_limit
|
33
|
-
- **retry_wait
|
34
|
-
- **max_retry_wait
|
32
|
+
- **retry_limit**: max retry count for database operations (integer, default: 12)
|
33
|
+
- **retry_wait**: initial retry wait time in milliseconds (integer, default: 1000 (1 second))
|
34
|
+
- **max_retry_wait**: upper limit of retry wait, which will be doubled at every retry (integer, default: 1800000 (30 minutes))
|
35
35
|
- **mode**: "insert", "insert_direct", "truncate_insert" , "replace" or "merge". See below. (string, required)
|
36
36
|
- **merge_keys**: key column names for merging records in merge mode (string array, required in merge mode if table doesn't have primary key)
|
37
37
|
- **merge_rule**: list of column assignments for updating existing records used in merge mode, for example `foo = T.foo + S.foo` (`T` means target table and `S` means source table). (string array, default: always overwrites with new values)
|
Binary file
|
Binary file
|
@@ -21,6 +21,8 @@ import com.google.common.base.Optional;
|
|
21
21
|
|
22
22
|
public class NativeClientWrapper
|
23
23
|
{
|
24
|
+
private static int MAX_COLUMN_SIZE_FOR_BCP_BIND = 7999;
|
25
|
+
|
24
26
|
private static ODBC odbc;
|
25
27
|
private static NativeClient client;
|
26
28
|
|
@@ -206,11 +208,19 @@ public class NativeClientWrapper
|
|
206
208
|
odbcHandle,
|
207
209
|
pointer,
|
208
210
|
0,
|
209
|
-
size,
|
211
|
+
Math.min(size, MAX_COLUMN_SIZE_FOR_BCP_BIND),
|
210
212
|
null,
|
211
213
|
0,
|
212
214
|
NativeClient.SQLCHARACTER,
|
213
215
|
columnIndex));
|
216
|
+
|
217
|
+
if (size > MAX_COLUMN_SIZE_FOR_BCP_BIND) {
|
218
|
+
checkBCPResult("bcp_collen", client.bcp_collen(
|
219
|
+
odbcHandle,
|
220
|
+
size,
|
221
|
+
columnIndex));
|
222
|
+
}
|
223
|
+
|
214
224
|
return (int)pointer.size();
|
215
225
|
}
|
216
226
|
|
@@ -8,10 +8,15 @@ import static org.junit.Assert.assertThat;
|
|
8
8
|
import java.io.File;
|
9
9
|
import java.net.URISyntaxException;
|
10
10
|
import java.net.URL;
|
11
|
+
import java.nio.charset.Charset;
|
11
12
|
import java.nio.file.FileSystems;
|
13
|
+
import java.nio.file.Files;
|
12
14
|
import java.nio.file.Path;
|
15
|
+
import java.sql.Connection;
|
16
|
+
import java.sql.ResultSet;
|
17
|
+
import java.sql.Statement;
|
18
|
+
import java.util.List;
|
13
19
|
|
14
|
-
import org.embulk.config.ConfigDiff;
|
15
20
|
import org.embulk.config.ConfigSource;
|
16
21
|
import org.embulk.output.SQLServerOutputPlugin;
|
17
22
|
import org.embulk.spi.OutputPlugin;
|
@@ -21,6 +26,7 @@ import org.junit.Before;
|
|
21
26
|
import org.junit.Rule;
|
22
27
|
import org.junit.Test;
|
23
28
|
|
29
|
+
import com.google.common.collect.ImmutableList;
|
24
30
|
import com.google.common.io.Resources;
|
25
31
|
|
26
32
|
public class NativeTest
|
@@ -249,6 +255,59 @@ public class NativeTest
|
|
249
255
|
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
250
256
|
}
|
251
257
|
|
258
|
+
@Test
|
259
|
+
public void testHuge() throws Exception
|
260
|
+
{
|
261
|
+
Path in1 = toPath("test_huge.csv");
|
262
|
+
|
263
|
+
// create input data dynamically because it is huge.
|
264
|
+
|
265
|
+
ImmutableList.Builder<String[]> recordsBuilder = ImmutableList.builder();
|
266
|
+
recordsBuilder.add(new String[]{"a", "X", "あ"});
|
267
|
+
recordsBuilder.add(new String[]{"b", createString(9000), createString(10000) + "い"});
|
268
|
+
recordsBuilder.add(new String[]{"c", createString(20000), createString(30000) + "う"});
|
269
|
+
List<String[]> records = recordsBuilder.build();
|
270
|
+
|
271
|
+
ImmutableList.Builder<String> linesBuilder = ImmutableList.builder();
|
272
|
+
linesBuilder.add("ITEM1:long,ITEM2:string,ITEM3:string,ITEM4:string");
|
273
|
+
for (int i = 0; i < records.size(); i++) {
|
274
|
+
String[] record = records.get(i);
|
275
|
+
linesBuilder.add((i + 1) + "," + record[0] + "," + record[1] + "," + record[2]);
|
276
|
+
}
|
277
|
+
|
278
|
+
Charset charset = Charset.forName("UTF8");
|
279
|
+
Files.write(in1, linesBuilder.build(), charset);
|
280
|
+
|
281
|
+
TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_huge.yml")), in1);
|
282
|
+
//assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
|
283
|
+
|
284
|
+
try (Connection conn = SQLServerTests.connect()) {
|
285
|
+
try (Statement statement = conn.createStatement()) {
|
286
|
+
try (ResultSet rs = statement.executeQuery("SELECT * FROM TEST_HUGE ORDER BY ITEM1")) {
|
287
|
+
int recordIndex = 0;
|
288
|
+
while (rs.next()) {
|
289
|
+
assertThat(rs.getInt(1), is(recordIndex + 1));
|
290
|
+
assertThat(rs.getString(2), is(records.get(recordIndex)[0]));
|
291
|
+
assertThat(rs.getString(3), is(records.get(recordIndex)[1]));
|
292
|
+
assertThat(rs.getString(4), is(records.get(recordIndex)[2]));
|
293
|
+
recordIndex++;
|
294
|
+
}
|
295
|
+
|
296
|
+
assertThat(recordIndex, is(records.size()));
|
297
|
+
}
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
private String createString(int size)
|
303
|
+
{
|
304
|
+
char[] chars = new char[size];
|
305
|
+
for (int i = 0; i < size; i++) {
|
306
|
+
chars[i] = (char)('A' + i % 26);
|
307
|
+
}
|
308
|
+
return new String(chars);
|
309
|
+
}
|
310
|
+
|
252
311
|
private Path toPath(String fileName) throws URISyntaxException
|
253
312
|
{
|
254
313
|
URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
|
@@ -6,6 +6,9 @@ import java.io.IOException;
|
|
6
6
|
import java.nio.charset.Charset;
|
7
7
|
import java.nio.file.Files;
|
8
8
|
import java.nio.file.Path;
|
9
|
+
import java.sql.Connection;
|
10
|
+
import java.sql.DriverManager;
|
11
|
+
import java.sql.SQLException;
|
9
12
|
import java.util.Collections;
|
10
13
|
import java.util.List;
|
11
14
|
|
@@ -24,6 +27,21 @@ public class SQLServerTests
|
|
24
27
|
return EmbulkTests.config("EMBULK_OUTPUT_SQLSERVER_TEST_CONFIG");
|
25
28
|
}
|
26
29
|
|
30
|
+
public static Connection connect() throws SQLException
|
31
|
+
{
|
32
|
+
ConfigSource config = baseConfig();
|
33
|
+
|
34
|
+
String user = config.get(String.class, "user");
|
35
|
+
String password = config.get(String.class, "password");
|
36
|
+
String host = config.get(String.class, "host");
|
37
|
+
Integer port = config.get(Integer.class, "port");
|
38
|
+
String database = config.get(String.class, "database");
|
39
|
+
|
40
|
+
String url = String.format("jdbc:jtds:sqlserver://%s:%d/%s", host, port, database);
|
41
|
+
|
42
|
+
return DriverManager.getConnection(url, user, password);
|
43
|
+
}
|
44
|
+
|
27
45
|
public static void execute(String sql, String... options)
|
28
46
|
{
|
29
47
|
ConfigSource config = baseConfig();
|
@@ -0,0 +1 @@
|
|
1
|
+
dummy
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-sqlserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.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:
|
11
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -19,8 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- build.gradle
|
22
|
-
- classpath/embulk-output-jdbc-0.8.
|
23
|
-
- classpath/embulk-output-sqlserver-0.8.
|
22
|
+
- classpath/embulk-output-jdbc-0.8.1.jar
|
23
|
+
- classpath/embulk-output-sqlserver-0.8.1.jar
|
24
24
|
- classpath/jtds-1.3.1.jar
|
25
25
|
- lib/embulk/output/sqlserver.rb
|
26
26
|
- src/main/java/org/embulk/output/SQLServerOutputPlugin.java
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_float_null.csv
|
80
80
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_float_null.yml
|
81
81
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_float_null_expected.csv
|
82
|
+
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_huge.csv
|
83
|
+
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_huge.yml
|
82
84
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_int_null.yml
|
83
85
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_integer_null.csv
|
84
86
|
- src/test/resources/org/embulk/output/sqlserver/test/expect/native/test_integer_null_expected.csv
|