embulk-output-oracle 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-oracle-0.7.10.jar → embulk-output-oracle-0.7.11.jar} +0 -0
- data/src/test/java/org/embulk/output/oracle/BasicTest.java +450 -0
- data/src/test/java/org/embulk/output/oracle/DummyFileSystem.java +96 -0
- data/src/test/java/org/embulk/output/oracle/DummyFileSystemProvider.java +154 -0
- data/src/test/java/org/embulk/output/oracle/DummyPath.java +188 -0
- data/src/test/java/org/embulk/output/oracle/OracleTests.java +90 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/setup.sql +54 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test1.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_expected.diff +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_create_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_direct.yml +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_large.yml +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_multibyte_table.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_oci.yml +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_oci_large.yml +6 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_direct_oci_multibyte_table.yml +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_empty_expected.csv +1 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_large_expected.csv +9999 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_insert_multibyte_table.yml +2 -0
- data/src/test/resources/{oracle/data/test3/test3.csv → org/embulk/output/oracle/test/expect/basic/test_large.csv} +3 -3
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_lower_column.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_lower_column.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_lower_column_options.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_lower_column_options.yml +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_lower_table.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge.csv +6 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_expected.csv +6 -0
- data/src/test/resources/{oracle/data/test5/test5.csv → org/embulk/output/oracle/test/expect/basic/test_merge_keys.csv} +5 -4
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_keys.yml +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_keys_expected.csv +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_rule.csv +6 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_rule.yml +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_merge_rule_expected.csv +6 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_replace.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_replace_column_options.yml +10 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_replace_longname.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_replace_longname_multibyte.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_replace_oci.yml +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_string_timestamp.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_string_timestamp.yml +5 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_string_timestamp_expected.csv +4 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_truncate_insert.yml +2 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_truncate_insert_expected.csv +3 -0
- data/src/test/resources/org/embulk/output/oracle/test/expect/basic/test_truncate_insert_oci.yml +3 -0
- metadata +51 -36
- data/src/test/java/org/embulk/input/filesplit/LocalFileSplitInputPlugin.java +0 -185
- data/src/test/java/org/embulk/input/filesplit/PartialFile.java +0 -50
- data/src/test/java/org/embulk/input/filesplit/PartialFileInputStream.java +0 -154
- data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java +0 -887
- data/src/test/resources/oracle/data/test1/test1.csv +0 -3
- data/src/test/resources/oracle/data/test4/test4.csv +0 -5
- data/src/test/resources/oracle/yml/test-insert-direct-direct-method.yml +0 -27
- data/src/test/resources/oracle/yml/test-insert-direct-empty.yml +0 -26
- data/src/test/resources/oracle/yml/test-insert-direct-oci-method-large.yml +0 -29
- data/src/test/resources/oracle/yml/test-insert-direct-oci-method-multibyte.yml +0 -29
- data/src/test/resources/oracle/yml/test-insert-direct-oci-method-split.yml +0 -29
- data/src/test/resources/oracle/yml/test-insert-direct-oci-method.yml +0 -29
- data/src/test/resources/oracle/yml/test-insert-direct.yml +0 -26
- data/src/test/resources/oracle/yml/test-insert-empty.yml +0 -28
- data/src/test/resources/oracle/yml/test-insert.yml +0 -26
- data/src/test/resources/oracle/yml/test-lower-column-options.yml +0 -29
- data/src/test/resources/oracle/yml/test-lower-column.yml +0 -26
- data/src/test/resources/oracle/yml/test-lower-table.yml +0 -26
- data/src/test/resources/oracle/yml/test-merge-keys.yml +0 -23
- data/src/test/resources/oracle/yml/test-merge-rule.yml +0 -23
- data/src/test/resources/oracle/yml/test-merge.yml +0 -22
- data/src/test/resources/oracle/yml/test-replace-empty.yml +0 -33
- data/src/test/resources/oracle/yml/test-replace-long-name-multibyte.yml +0 -33
- data/src/test/resources/oracle/yml/test-replace-long-name.yml +0 -33
- data/src/test/resources/oracle/yml/test-replace-oci-method.yml +0 -34
- data/src/test/resources/oracle/yml/test-replace.yml +0 -33
- data/src/test/resources/oracle/yml/test-string-timestamp.yml +0 -29
- data/src/test/resources/oracle/yml/test-truncate-insert-oci-method.yml +0 -27
- data/src/test/resources/oracle/yml/test-truncate-insert.yml +0 -26
- data/src/test/resources/oracle/yml/test-url.yml +0 -25
@@ -1,50 +0,0 @@
|
|
1
|
-
package org.embulk.input.filesplit;
|
2
|
-
|
3
|
-
public class PartialFile
|
4
|
-
{
|
5
|
-
private String path;
|
6
|
-
private long start;
|
7
|
-
private long end;
|
8
|
-
|
9
|
-
|
10
|
-
public PartialFile(String path, long start, long end)
|
11
|
-
{
|
12
|
-
this.path = path;
|
13
|
-
this.start = start;
|
14
|
-
this.end = end;
|
15
|
-
}
|
16
|
-
|
17
|
-
public PartialFile() {
|
18
|
-
}
|
19
|
-
|
20
|
-
public String getPath()
|
21
|
-
{
|
22
|
-
return path;
|
23
|
-
}
|
24
|
-
|
25
|
-
public void setPath(String path)
|
26
|
-
{
|
27
|
-
this.path = path;
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
public long getStart()
|
32
|
-
{
|
33
|
-
return start;
|
34
|
-
}
|
35
|
-
|
36
|
-
public void setStart(long start)
|
37
|
-
{
|
38
|
-
this.start = start;
|
39
|
-
}
|
40
|
-
|
41
|
-
public long getEnd()
|
42
|
-
{
|
43
|
-
return end;
|
44
|
-
}
|
45
|
-
|
46
|
-
public void setEnd(long end)
|
47
|
-
{
|
48
|
-
this.end = end;
|
49
|
-
}
|
50
|
-
}
|
@@ -1,154 +0,0 @@
|
|
1
|
-
package org.embulk.input.filesplit;
|
2
|
-
|
3
|
-
import java.io.BufferedInputStream;
|
4
|
-
import java.io.IOException;
|
5
|
-
import java.io.InputStream;
|
6
|
-
import java.io.PushbackInputStream;
|
7
|
-
|
8
|
-
|
9
|
-
public class PartialFileInputStream extends InputStream
|
10
|
-
{
|
11
|
-
private final PushbackInputStream original;
|
12
|
-
private long start;
|
13
|
-
private long end;
|
14
|
-
private long current;
|
15
|
-
private boolean eof;
|
16
|
-
|
17
|
-
public PartialFileInputStream(InputStream original, long start, long end)
|
18
|
-
{
|
19
|
-
this.original = new PushbackInputStream(new BufferedInputStream(original));
|
20
|
-
this.start = start;
|
21
|
-
this.end = end;
|
22
|
-
current = -1;
|
23
|
-
}
|
24
|
-
|
25
|
-
@Override
|
26
|
-
public int read(byte[] b) throws IOException
|
27
|
-
{
|
28
|
-
return read(b, 0, b.length);
|
29
|
-
}
|
30
|
-
|
31
|
-
@Override
|
32
|
-
public int read(byte[] b, int off, int len) throws IOException
|
33
|
-
{
|
34
|
-
initializeIfNeeded();
|
35
|
-
|
36
|
-
if (eof) {
|
37
|
-
return -1;
|
38
|
-
}
|
39
|
-
|
40
|
-
int read = original.read(b, off, len);
|
41
|
-
if (read < 0) {
|
42
|
-
eof = true;
|
43
|
-
return -1;
|
44
|
-
}
|
45
|
-
|
46
|
-
current += read;
|
47
|
-
if (current >= end) {
|
48
|
-
for (int i = Math.max((int)(end - 1 - current + read), 0); i < read; i++) {
|
49
|
-
if (b[off + i] == '\n') {
|
50
|
-
eof = true;
|
51
|
-
return i + 1;
|
52
|
-
}
|
53
|
-
|
54
|
-
if (b[off + i] == '\r') {
|
55
|
-
int next = (i < read ? b[off + i + 1] : prefetch());
|
56
|
-
if (next != '\n') {
|
57
|
-
eof = true;
|
58
|
-
return i + 1;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
return read;
|
65
|
-
}
|
66
|
-
|
67
|
-
@Override
|
68
|
-
public int read() throws IOException
|
69
|
-
{
|
70
|
-
initializeIfNeeded();
|
71
|
-
|
72
|
-
if (eof) {
|
73
|
-
return -1;
|
74
|
-
}
|
75
|
-
|
76
|
-
int read = original.read();
|
77
|
-
current++;
|
78
|
-
|
79
|
-
if (read < 0) {
|
80
|
-
eof = true;
|
81
|
-
return -1;
|
82
|
-
}
|
83
|
-
|
84
|
-
if (current >= end) {
|
85
|
-
if (read == '\n' || read == '\r' && prefetch() != '\n') {
|
86
|
-
eof = true;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
return read;
|
91
|
-
}
|
92
|
-
|
93
|
-
@Override
|
94
|
-
public long skip(long n) throws IOException
|
95
|
-
{
|
96
|
-
throw new IOException("Skip not supported.");
|
97
|
-
/*
|
98
|
-
long skip = original.skip(n);
|
99
|
-
current += skip;
|
100
|
-
return skip;
|
101
|
-
*/
|
102
|
-
}
|
103
|
-
|
104
|
-
@Override
|
105
|
-
public int available() throws IOException
|
106
|
-
{
|
107
|
-
return 0;
|
108
|
-
}
|
109
|
-
|
110
|
-
@Override
|
111
|
-
public void close() throws IOException
|
112
|
-
{
|
113
|
-
original.close();
|
114
|
-
}
|
115
|
-
|
116
|
-
private void initializeIfNeeded() throws IOException
|
117
|
-
{
|
118
|
-
if (current >= start) {
|
119
|
-
return;
|
120
|
-
|
121
|
-
}
|
122
|
-
if (start == 0) {
|
123
|
-
current = 0;
|
124
|
-
} else {
|
125
|
-
current = original.skip(--start);
|
126
|
-
if (current != start) {
|
127
|
-
throw new IOException("Cannot skip.");
|
128
|
-
}
|
129
|
-
|
130
|
-
int c;
|
131
|
-
while ((c = original.read()) >= 0) {
|
132
|
-
start++;
|
133
|
-
current++;
|
134
|
-
|
135
|
-
if (c == '\n' || c == '\r' && prefetch() != '\n') {
|
136
|
-
break;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
if (start >= end) {
|
142
|
-
eof = true;
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
private int prefetch() throws IOException
|
147
|
-
{
|
148
|
-
int c = original.read();
|
149
|
-
if (c >= 0) {
|
150
|
-
original.unread(c);
|
151
|
-
}
|
152
|
-
return c;
|
153
|
-
}
|
154
|
-
}
|
@@ -1,887 +0,0 @@
|
|
1
|
-
package org.embulk.output.oracle;
|
2
|
-
|
3
|
-
import static java.util.Locale.ENGLISH;
|
4
|
-
import static org.junit.Assert.assertEquals;
|
5
|
-
import static org.junit.Assert.fail;
|
6
|
-
|
7
|
-
import java.io.File;
|
8
|
-
import java.lang.reflect.Constructor;
|
9
|
-
import java.math.BigDecimal;
|
10
|
-
import java.sql.Connection;
|
11
|
-
import java.sql.DriverManager;
|
12
|
-
import java.sql.ResultSet;
|
13
|
-
import java.sql.SQLException;
|
14
|
-
import java.sql.Timestamp;
|
15
|
-
import java.text.DateFormat;
|
16
|
-
import java.text.ParseException;
|
17
|
-
import java.text.SimpleDateFormat;
|
18
|
-
import java.util.Date;
|
19
|
-
import java.util.Iterator;
|
20
|
-
import java.util.List;
|
21
|
-
import java.util.TimeZone;
|
22
|
-
|
23
|
-
import org.embulk.exec.PartialExecutionException;
|
24
|
-
import org.embulk.input.filesplit.LocalFileSplitInputPlugin;
|
25
|
-
import org.embulk.output.AbstractJdbcOutputPluginTest;
|
26
|
-
import org.embulk.output.OracleOutputPlugin;
|
27
|
-
import org.embulk.spi.InputPlugin;
|
28
|
-
import org.embulk.spi.OutputPlugin;
|
29
|
-
import org.junit.Test;
|
30
|
-
|
31
|
-
|
32
|
-
public class OracleOutputPluginTest extends AbstractJdbcOutputPluginTest
|
33
|
-
{
|
34
|
-
@Override
|
35
|
-
protected void prepare() throws SQLException
|
36
|
-
{
|
37
|
-
tester.addPlugin(OutputPlugin.class, "oracle", OracleOutputPlugin.class);
|
38
|
-
tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class);
|
39
|
-
|
40
|
-
if (System.getProperty("path.separator").equals(";")) {
|
41
|
-
// for Windows
|
42
|
-
System.setProperty("file.encoding", "MS932");
|
43
|
-
}
|
44
|
-
|
45
|
-
try {
|
46
|
-
Class.forName("oracle.jdbc.OracleDriver");
|
47
|
-
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
48
|
-
System.err.println("Warning: you should put 'ojdbc7.jar' in 'embulk-output-oracle/driver' directory in order to test.");
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
|
52
|
-
try (Connection connection = connect()) {
|
53
|
-
String version = connection.getMetaData().getDriverVersion();
|
54
|
-
System.out.println("Driver version = " + version);
|
55
|
-
enabled = true;
|
56
|
-
|
57
|
-
} catch (SQLException e) {
|
58
|
-
System.err.println(e);
|
59
|
-
System.err.println(String.format(ENGLISH, "Warning: prepare a schema on Oracle 12c (server = %s, port = %d, database = %s, user = %s, password = %s, charset = UTF-8).",
|
60
|
-
getHost(), getPort(), getDatabase(), getUser(), getPassword()));
|
61
|
-
// for example
|
62
|
-
// CREATE USER EMBULK_USER IDENTIFIED BY "embulk_pw";
|
63
|
-
// GRANT DBA TO EMBULK_USER;
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
@Test
|
68
|
-
public void testInsert() throws Exception
|
69
|
-
{
|
70
|
-
String table = "TEST1";
|
71
|
-
|
72
|
-
dropTable(table);
|
73
|
-
createTable(table);
|
74
|
-
|
75
|
-
test("/oracle/yml/test-insert.yml");
|
76
|
-
|
77
|
-
assertTable(table);
|
78
|
-
}
|
79
|
-
|
80
|
-
@Test
|
81
|
-
public void testInsertCreate() throws Exception
|
82
|
-
{
|
83
|
-
String table = "TEST1";
|
84
|
-
|
85
|
-
dropTable(table);
|
86
|
-
|
87
|
-
test("/oracle/yml/test-insert.yml");
|
88
|
-
|
89
|
-
assertGeneratedTable1(table);
|
90
|
-
}
|
91
|
-
|
92
|
-
@Test
|
93
|
-
public void testInsertEmpty() throws Exception
|
94
|
-
{
|
95
|
-
String table = "TEST1";
|
96
|
-
|
97
|
-
dropTable(table);
|
98
|
-
createTable(table);
|
99
|
-
|
100
|
-
new File(convertPath("/oracle/data/"), "test2").mkdir();
|
101
|
-
test("/oracle/yml/test-insert-empty.yml");
|
102
|
-
|
103
|
-
assertTableEmpty(table);
|
104
|
-
}
|
105
|
-
|
106
|
-
@Test
|
107
|
-
public void testTruncateInsert() throws Exception
|
108
|
-
{
|
109
|
-
String table = "TEST1";
|
110
|
-
|
111
|
-
dropTable(table);
|
112
|
-
createTable(table);
|
113
|
-
insertRecord(table);
|
114
|
-
|
115
|
-
test("/oracle/yml/test-truncate-insert.yml");
|
116
|
-
|
117
|
-
assertTable(table);
|
118
|
-
}
|
119
|
-
|
120
|
-
@Test
|
121
|
-
public void testTruncateInsertOCIMethod() throws Exception
|
122
|
-
{
|
123
|
-
String table = "TEST1";
|
124
|
-
|
125
|
-
dropTable(table);
|
126
|
-
createTable(table);
|
127
|
-
insertRecord(table);
|
128
|
-
|
129
|
-
test("/oracle/yml/test-truncate-insert-oci-method.yml");
|
130
|
-
|
131
|
-
assertTable(table);
|
132
|
-
}
|
133
|
-
|
134
|
-
@Test
|
135
|
-
public void testTruncateInsertCreate() throws Exception
|
136
|
-
{
|
137
|
-
String table = "TEST1";
|
138
|
-
|
139
|
-
dropTable(table);
|
140
|
-
|
141
|
-
test("/oracle/yml/test-truncate-insert.yml");
|
142
|
-
|
143
|
-
assertGeneratedTable1(table);
|
144
|
-
}
|
145
|
-
|
146
|
-
@Test
|
147
|
-
public void testInsertDirect() throws Exception
|
148
|
-
{
|
149
|
-
String table = "TEST1";
|
150
|
-
|
151
|
-
dropTable(table);
|
152
|
-
createTable(table);
|
153
|
-
|
154
|
-
test("/oracle/yml/test-insert-direct.yml");
|
155
|
-
|
156
|
-
assertTable(table);
|
157
|
-
}
|
158
|
-
|
159
|
-
@Test
|
160
|
-
public void testInsertDirectDuplicate() throws Exception
|
161
|
-
{
|
162
|
-
if (!enabled) {
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
|
166
|
-
String table = "TEST1";
|
167
|
-
|
168
|
-
dropTable(table);
|
169
|
-
createTable(table);
|
170
|
-
insertRecord(table, "A002");
|
171
|
-
|
172
|
-
try {
|
173
|
-
test("/oracle/yml/test-insert-direct.yml");
|
174
|
-
fail("Exception expected.");
|
175
|
-
} catch (Exception e) {
|
176
|
-
System.out.println(e);
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
@Test
|
181
|
-
public void testInsertDirectEmpty() throws Exception
|
182
|
-
{
|
183
|
-
String table = "TEST1";
|
184
|
-
|
185
|
-
dropTable(table);
|
186
|
-
createTable(table);
|
187
|
-
|
188
|
-
new File(convertPath("/oracle/data/"), "test2").mkdir();
|
189
|
-
test("/oracle/yml/test-insert-direct-empty.yml");
|
190
|
-
|
191
|
-
assertTableEmpty(table);
|
192
|
-
}
|
193
|
-
|
194
|
-
@Test
|
195
|
-
public void testInsertDirectCreate() throws Exception
|
196
|
-
{
|
197
|
-
String table = "TEST1";
|
198
|
-
|
199
|
-
dropTable(table);
|
200
|
-
|
201
|
-
test("/oracle/yml/test-insert-direct.yml");
|
202
|
-
|
203
|
-
assertGeneratedTable1(table);
|
204
|
-
}
|
205
|
-
|
206
|
-
@Test
|
207
|
-
public void testInsertDirectDirectMethod() throws Exception
|
208
|
-
{
|
209
|
-
String table = "TEST1";
|
210
|
-
|
211
|
-
dropTable(table);
|
212
|
-
createTable(table);
|
213
|
-
|
214
|
-
try {
|
215
|
-
test("/oracle/yml/test-insert-direct-direct-method.yml");
|
216
|
-
} catch (PartialExecutionException e) {
|
217
|
-
if (e.getCause() != null && e.getCause().getClass().equals(RuntimeException.class)
|
218
|
-
&& e.getCause().getCause() != null && e.getCause().getCause().getClass().equals(AssertionError.class)) {
|
219
|
-
// ignore error
|
220
|
-
e.printStackTrace();
|
221
|
-
System.err.println("The 'direct' mode works if running embulk directly, but fails if using EmbulkPluginTester.");
|
222
|
-
return;
|
223
|
-
}
|
224
|
-
throw e;
|
225
|
-
}
|
226
|
-
|
227
|
-
assertTable(table);
|
228
|
-
}
|
229
|
-
|
230
|
-
@Test
|
231
|
-
public void testInsertDirectOCIMethod() throws Exception
|
232
|
-
{
|
233
|
-
String table = "TEST1";
|
234
|
-
|
235
|
-
dropTable(table);
|
236
|
-
createTable(table);
|
237
|
-
|
238
|
-
test("/oracle/yml/test-insert-direct-oci-method.yml");
|
239
|
-
|
240
|
-
assertTable(table);
|
241
|
-
}
|
242
|
-
|
243
|
-
@Test
|
244
|
-
public void testInsertDirectOCIMethodLarge() throws Exception
|
245
|
-
{
|
246
|
-
if (!enabled) {
|
247
|
-
return;
|
248
|
-
}
|
249
|
-
|
250
|
-
String table = "TEST1";
|
251
|
-
|
252
|
-
dropTable(table);
|
253
|
-
createTable(table);
|
254
|
-
|
255
|
-
test("/oracle/yml/test-insert-direct-oci-method-large.yml");
|
256
|
-
|
257
|
-
List<List<Object>> rows = select(table);
|
258
|
-
assertEquals(9999, rows.size());
|
259
|
-
for (int i = 0; i < rows.size(); i++) {
|
260
|
-
assertEquals(String.format("%04d", i + 1), rows.get(i).get(0));
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
@Test
|
265
|
-
public void testInsertDirectOCIMethodDuplicate() throws Exception
|
266
|
-
{
|
267
|
-
if (!enabled) {
|
268
|
-
return;
|
269
|
-
}
|
270
|
-
|
271
|
-
String table = "TEST1";
|
272
|
-
|
273
|
-
dropTable(table);
|
274
|
-
createTable(table);
|
275
|
-
insertRecord(table, "A002");
|
276
|
-
|
277
|
-
try {
|
278
|
-
test("/oracle/yml/test-insert-direct-oci-method.yml");
|
279
|
-
fail("Exception expected.");
|
280
|
-
} catch (Exception e) {
|
281
|
-
System.out.println(e);
|
282
|
-
}
|
283
|
-
}
|
284
|
-
|
285
|
-
@Test
|
286
|
-
public void testInsertDirectOCIMethodMultibyte() throws Exception
|
287
|
-
{
|
288
|
-
String table = "TEST1";
|
289
|
-
|
290
|
-
dropTable(table);
|
291
|
-
createTable(table);
|
292
|
-
|
293
|
-
test("/oracle/yml/test-insert-direct-oci-method-multibyte.yml");
|
294
|
-
|
295
|
-
assertTable(table);
|
296
|
-
}
|
297
|
-
|
298
|
-
@Test
|
299
|
-
public void testInsertDirectOCIMethodMultibyteDuplicate() throws Exception
|
300
|
-
{
|
301
|
-
if (!enabled) {
|
302
|
-
return;
|
303
|
-
}
|
304
|
-
|
305
|
-
String table = "TEST1";
|
306
|
-
|
307
|
-
dropTable(table);
|
308
|
-
createTable(table);
|
309
|
-
insertRecord(table, "A002");
|
310
|
-
|
311
|
-
try {
|
312
|
-
test("/oracle/yml/test-insert-direct-oci-method-multibyte.yml");
|
313
|
-
fail("Exception expected.");
|
314
|
-
} catch (Exception e) {
|
315
|
-
System.out.println(e);
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
|
-
@Test
|
320
|
-
public void testInsertDirectOCIMethodSplit() throws Exception
|
321
|
-
{
|
322
|
-
String table = "TEST1";
|
323
|
-
|
324
|
-
dropTable(table);
|
325
|
-
createTable(table);
|
326
|
-
|
327
|
-
test("/oracle/yml/test-insert-direct-oci-method-split.yml");
|
328
|
-
|
329
|
-
assertTable(table);
|
330
|
-
}
|
331
|
-
|
332
|
-
@Test
|
333
|
-
public void testMerge() throws Exception
|
334
|
-
{
|
335
|
-
if (!enabled) {
|
336
|
-
return;
|
337
|
-
}
|
338
|
-
|
339
|
-
String table = "TEST1";
|
340
|
-
|
341
|
-
dropTable(table);
|
342
|
-
executeSQL("CREATE TABLE TEST1 ("
|
343
|
-
+ "ID CHAR(4),"
|
344
|
-
+ "VARCHAR2_ITEM VARCHAR2(6),"
|
345
|
-
+ "NUMBER_ITEM NUMBER(10,2),"
|
346
|
-
+ "PRIMARY KEY (ID))");
|
347
|
-
executeSQL("INSERT INTO TEST1 VALUES('A001', 'AAA', 12.34)");
|
348
|
-
executeSQL("INSERT INTO TEST1 VALUES('A003', NULL, NULL)");
|
349
|
-
executeSQL("INSERT INTO TEST1 VALUES('A005', 'EEE', 56.78)");
|
350
|
-
executeSQL("INSERT INTO TEST1 VALUES('A006', 'FFF', 0)");
|
351
|
-
|
352
|
-
test("/oracle/yml/test-merge.yml");
|
353
|
-
|
354
|
-
List<List<Object>> rows = select(table);
|
355
|
-
assertEquals(6, rows.size());
|
356
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
357
|
-
{
|
358
|
-
Iterator<Object> i2 = i1.next().iterator();
|
359
|
-
assertEquals("A001", i2.next());
|
360
|
-
assertEquals("aaa", i2.next());
|
361
|
-
assertEquals(new BigDecimal("99.99"), i2.next());
|
362
|
-
}
|
363
|
-
{
|
364
|
-
Iterator<Object> i2 = i1.next().iterator();
|
365
|
-
assertEquals("A002", i2.next());
|
366
|
-
assertEquals("bbb", i2.next());
|
367
|
-
assertEquals(new BigDecimal("88.88"), i2.next());
|
368
|
-
}
|
369
|
-
{
|
370
|
-
Iterator<Object> i2 = i1.next().iterator();
|
371
|
-
assertEquals("A003", i2.next());
|
372
|
-
assertEquals("ccc", i2.next());
|
373
|
-
assertEquals(new BigDecimal("77.77"), i2.next());
|
374
|
-
}
|
375
|
-
{
|
376
|
-
Iterator<Object> i2 = i1.next().iterator();
|
377
|
-
assertEquals("A004", i2.next());
|
378
|
-
assertEquals(null, i2.next());
|
379
|
-
assertEquals(null, i2.next());
|
380
|
-
}
|
381
|
-
{
|
382
|
-
Iterator<Object> i2 = i1.next().iterator();
|
383
|
-
assertEquals("A005", i2.next());
|
384
|
-
assertEquals(null, i2.next());
|
385
|
-
assertEquals(null, i2.next());
|
386
|
-
}
|
387
|
-
{
|
388
|
-
Iterator<Object> i2 = i1.next().iterator();
|
389
|
-
assertEquals("A006", i2.next());
|
390
|
-
assertEquals("FFF", i2.next());
|
391
|
-
assertEquals(new BigDecimal("0"), i2.next());
|
392
|
-
}
|
393
|
-
}
|
394
|
-
|
395
|
-
@Test
|
396
|
-
public void testMergeWithKeys() throws Exception
|
397
|
-
{
|
398
|
-
if (!enabled) {
|
399
|
-
return;
|
400
|
-
}
|
401
|
-
|
402
|
-
String table = "TEST1";
|
403
|
-
|
404
|
-
dropTable(table);
|
405
|
-
executeSQL("CREATE TABLE TEST1 ("
|
406
|
-
+ "ID CHAR(4),"
|
407
|
-
+ "VARCHAR2_ITEM VARCHAR2(6),"
|
408
|
-
+ "NUMBER_ITEM NUMBER(10,2),"
|
409
|
-
+ "PRIMARY KEY (ID))");
|
410
|
-
executeSQL("INSERT INTO TEST1 VALUES('A001', 'AAA', 11.11)");
|
411
|
-
executeSQL("INSERT INTO TEST1 VALUES('A002', 'BBB', 22.22)");
|
412
|
-
executeSQL("INSERT INTO TEST1 VALUES('A003', 'CCC', 33.33)");
|
413
|
-
|
414
|
-
test("/oracle/yml/test-merge-keys.yml");
|
415
|
-
|
416
|
-
List<List<Object>> rows = select(table);
|
417
|
-
assertEquals(5, rows.size());
|
418
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
419
|
-
{
|
420
|
-
Iterator<Object> i2 = i1.next().iterator();
|
421
|
-
assertEquals("A001", i2.next());
|
422
|
-
assertEquals("AAA", i2.next());
|
423
|
-
assertEquals(new BigDecimal("11.11"), i2.next());
|
424
|
-
}
|
425
|
-
{
|
426
|
-
Iterator<Object> i2 = i1.next().iterator();
|
427
|
-
assertEquals("A004", i2.next());
|
428
|
-
assertEquals("BBB", i2.next());
|
429
|
-
assertEquals(new BigDecimal("22.21"), i2.next());
|
430
|
-
}
|
431
|
-
{
|
432
|
-
Iterator<Object> i2 = i1.next().iterator();
|
433
|
-
assertEquals("A005", i2.next());
|
434
|
-
assertEquals("BBB", i2.next());
|
435
|
-
assertEquals(new BigDecimal("22.22"), i2.next());
|
436
|
-
}
|
437
|
-
{
|
438
|
-
Iterator<Object> i2 = i1.next().iterator();
|
439
|
-
assertEquals("A006", i2.next());
|
440
|
-
assertEquals("BBB", i2.next());
|
441
|
-
assertEquals(new BigDecimal("22.23"), i2.next());
|
442
|
-
}
|
443
|
-
{
|
444
|
-
Iterator<Object> i2 = i1.next().iterator();
|
445
|
-
assertEquals("A007", i2.next());
|
446
|
-
assertEquals("CCC", i2.next());
|
447
|
-
assertEquals(new BigDecimal("33.33"), i2.next());
|
448
|
-
}
|
449
|
-
}
|
450
|
-
|
451
|
-
@Test
|
452
|
-
public void testMergeWithRule() throws Exception
|
453
|
-
{
|
454
|
-
if (!enabled) {
|
455
|
-
return;
|
456
|
-
}
|
457
|
-
|
458
|
-
String table = "TEST1";
|
459
|
-
|
460
|
-
dropTable(table);
|
461
|
-
executeSQL("CREATE TABLE TEST1 ("
|
462
|
-
+ "ID CHAR(4),"
|
463
|
-
+ "VARCHAR2_ITEM VARCHAR2(6),"
|
464
|
-
+ "NUMBER_ITEM NUMBER(10,2),"
|
465
|
-
+ "PRIMARY KEY (ID))");
|
466
|
-
executeSQL("INSERT INTO TEST1 VALUES('A002', 'BBB', 22.22)");
|
467
|
-
executeSQL("INSERT INTO TEST1 VALUES('A004', 'DDD', 44.44)");
|
468
|
-
executeSQL("INSERT INTO TEST1 VALUES('A006', 'FFF', 66.66)");
|
469
|
-
|
470
|
-
/*
|
471
|
-
A001,aaa,99.99
|
472
|
-
A002,bbb,88.88
|
473
|
-
A003,ccc,77.77
|
474
|
-
A004,,
|
475
|
-
A005,,
|
476
|
-
*/
|
477
|
-
|
478
|
-
test("/oracle/yml/test-merge-rule.yml");
|
479
|
-
|
480
|
-
List<List<Object>> rows = select(table);
|
481
|
-
assertEquals(6, rows.size());
|
482
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
483
|
-
{
|
484
|
-
Iterator<Object> i2 = i1.next().iterator();
|
485
|
-
assertEquals("A001", i2.next());
|
486
|
-
assertEquals("aaa", i2.next());
|
487
|
-
assertEquals(new BigDecimal("99.99"), i2.next());
|
488
|
-
}
|
489
|
-
{
|
490
|
-
Iterator<Object> i2 = i1.next().iterator();
|
491
|
-
assertEquals("A002", i2.next());
|
492
|
-
assertEquals("x", i2.next());
|
493
|
-
assertEquals(new BigDecimal("111.1"), i2.next());
|
494
|
-
}
|
495
|
-
{
|
496
|
-
Iterator<Object> i2 = i1.next().iterator();
|
497
|
-
assertEquals("A003", i2.next());
|
498
|
-
assertEquals("ccc", i2.next());
|
499
|
-
assertEquals(new BigDecimal("77.77"), i2.next());
|
500
|
-
}
|
501
|
-
{
|
502
|
-
Iterator<Object> i2 = i1.next().iterator();
|
503
|
-
assertEquals("A004", i2.next());
|
504
|
-
assertEquals("x", i2.next());
|
505
|
-
assertEquals(null, i2.next());
|
506
|
-
}
|
507
|
-
{
|
508
|
-
Iterator<Object> i2 = i1.next().iterator();
|
509
|
-
assertEquals("A005", i2.next());
|
510
|
-
assertEquals(null, i2.next());
|
511
|
-
assertEquals(null, i2.next());
|
512
|
-
}
|
513
|
-
{
|
514
|
-
Iterator<Object> i2 = i1.next().iterator();
|
515
|
-
assertEquals("A006", i2.next());
|
516
|
-
assertEquals("FFF", i2.next());
|
517
|
-
assertEquals(new BigDecimal("66.66"), i2.next());
|
518
|
-
}
|
519
|
-
}
|
520
|
-
|
521
|
-
@Test
|
522
|
-
public void testUrl() throws Exception
|
523
|
-
{
|
524
|
-
String table = "TEST1";
|
525
|
-
|
526
|
-
dropTable(table);
|
527
|
-
createTable(table);
|
528
|
-
|
529
|
-
test("/oracle/yml/test-url.yml");
|
530
|
-
|
531
|
-
assertTable(table);
|
532
|
-
}
|
533
|
-
|
534
|
-
@Test
|
535
|
-
public void testLowerTable() throws Exception
|
536
|
-
{
|
537
|
-
String table = "TEST1";
|
538
|
-
|
539
|
-
dropTable(table);
|
540
|
-
createTable(table);
|
541
|
-
|
542
|
-
test("/oracle/yml/test-lower-table.yml");
|
543
|
-
|
544
|
-
assertTable(table);
|
545
|
-
}
|
546
|
-
|
547
|
-
@Test
|
548
|
-
public void testLowerColumn() throws Exception
|
549
|
-
{
|
550
|
-
String table = "TEST1";
|
551
|
-
|
552
|
-
dropTable(table);
|
553
|
-
createTable(table);
|
554
|
-
|
555
|
-
test("/oracle/yml/test-lower-column.yml");
|
556
|
-
|
557
|
-
assertTable(table);
|
558
|
-
}
|
559
|
-
|
560
|
-
@Test
|
561
|
-
public void testLowerColumnOptions() throws Exception
|
562
|
-
{
|
563
|
-
String table = "TEST1";
|
564
|
-
|
565
|
-
dropTable(table);
|
566
|
-
createTable(table);
|
567
|
-
|
568
|
-
test("/oracle/yml/test-lower-column-options.yml");
|
569
|
-
|
570
|
-
assertTable(table);
|
571
|
-
}
|
572
|
-
|
573
|
-
@Test
|
574
|
-
public void testReplace() throws Exception
|
575
|
-
{
|
576
|
-
String table = "TEST1";
|
577
|
-
|
578
|
-
dropTable(table);
|
579
|
-
createTable(table);
|
580
|
-
|
581
|
-
test("/oracle/yml/test-replace.yml");
|
582
|
-
|
583
|
-
assertGeneratedTable2(table);
|
584
|
-
}
|
585
|
-
|
586
|
-
@Test
|
587
|
-
public void testReplaceOCIMethod() throws Exception
|
588
|
-
{
|
589
|
-
String table = "TEST1";
|
590
|
-
|
591
|
-
dropTable(table);
|
592
|
-
createTable(table);
|
593
|
-
|
594
|
-
test("/oracle/yml/test-replace-oci-method.yml");
|
595
|
-
|
596
|
-
assertGeneratedTable2(table);
|
597
|
-
}
|
598
|
-
|
599
|
-
@Test
|
600
|
-
public void testReplaceEmpty() throws Exception
|
601
|
-
{
|
602
|
-
String table = "TEST1";
|
603
|
-
|
604
|
-
dropTable(table);
|
605
|
-
createTable(table);
|
606
|
-
|
607
|
-
test("/oracle/yml/test-replace-empty.yml");
|
608
|
-
|
609
|
-
assertTableEmpty(table);
|
610
|
-
}
|
611
|
-
|
612
|
-
@Test
|
613
|
-
public void testReplaceCreate() throws Exception
|
614
|
-
{
|
615
|
-
String table = "TEST1";
|
616
|
-
|
617
|
-
dropTable(table);
|
618
|
-
|
619
|
-
test("/oracle/yml/test-replace.yml");
|
620
|
-
|
621
|
-
assertGeneratedTable2(table);
|
622
|
-
}
|
623
|
-
|
624
|
-
|
625
|
-
@Test
|
626
|
-
public void testReplaceLongName() throws Exception
|
627
|
-
{
|
628
|
-
String table = "TEST12345678901234567890123456";
|
629
|
-
|
630
|
-
dropTable(table);
|
631
|
-
createTable(table);
|
632
|
-
|
633
|
-
test("/oracle/yml/test-replace-long-name.yml");
|
634
|
-
|
635
|
-
assertGeneratedTable2(table);
|
636
|
-
}
|
637
|
-
|
638
|
-
@Test
|
639
|
-
public void testReplaceLongNameMultibyte() throws Exception
|
640
|
-
{
|
641
|
-
String table = "TEST123456789012345678";
|
642
|
-
|
643
|
-
test("/oracle/yml/test-replace-long-name-multibyte.yml");
|
644
|
-
|
645
|
-
assertGeneratedTable2(table);
|
646
|
-
}
|
647
|
-
|
648
|
-
@Test
|
649
|
-
public void testStringTimestamp() throws Exception
|
650
|
-
{
|
651
|
-
String table = "TEST1";
|
652
|
-
|
653
|
-
dropTable(table);
|
654
|
-
createTable(table);
|
655
|
-
|
656
|
-
test("/oracle/yml/test-string-timestamp.yml");
|
657
|
-
|
658
|
-
assertTable(table);
|
659
|
-
}
|
660
|
-
|
661
|
-
private void createTable(String table) throws SQLException
|
662
|
-
{
|
663
|
-
String sql = String.format("CREATE TABLE %s ("
|
664
|
-
+ "ID CHAR(4),"
|
665
|
-
+ "VARCHAR2_ITEM VARCHAR2(6),"
|
666
|
-
+ "NVARCHAR2_ITEM NVARCHAR2(6),"
|
667
|
-
+ "INTEGER_ITEM NUMBER(4,0),"
|
668
|
-
+ "NUMBER_ITEM NUMBER(10,2),"
|
669
|
-
+ "DATE_ITEM DATE,"
|
670
|
-
+ "TIMESTAMP_ITEM TIMESTAMP,"
|
671
|
-
+ "PRIMARY KEY (ID))", table);
|
672
|
-
executeSQL(sql);
|
673
|
-
}
|
674
|
-
|
675
|
-
private void insertRecord(String table) throws SQLException
|
676
|
-
{
|
677
|
-
insertRecord(table, "9999");
|
678
|
-
}
|
679
|
-
|
680
|
-
private void insertRecord(String table, String id) throws SQLException
|
681
|
-
{
|
682
|
-
executeSQL(String.format("INSERT INTO %s VALUES('%s', NULL, NULL, NULL, NULL, NULL, NULL)", table, id));
|
683
|
-
}
|
684
|
-
|
685
|
-
private void assertTable(String table) throws Exception
|
686
|
-
{
|
687
|
-
if (!enabled) {
|
688
|
-
return;
|
689
|
-
}
|
690
|
-
|
691
|
-
// datetime of UTC will be inserted by embulk.
|
692
|
-
// datetime of default timezone will be selected by JDBC.
|
693
|
-
TimeZone timeZone = TimeZone.getDefault();
|
694
|
-
List<List<Object>> rows = select(table);
|
695
|
-
|
696
|
-
/*
|
697
|
-
A001,ABCDE,abcde,,0,123.45,2015/03/05,2015/03/05 12:34:56
|
698
|
-
A002,AB,abcdef,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
699
|
-
A003,,,,,,
|
700
|
-
*/
|
701
|
-
|
702
|
-
assertEquals(3, rows.size());
|
703
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
704
|
-
{
|
705
|
-
Iterator<Object> i2 = i1.next().iterator();
|
706
|
-
assertEquals("A001", i2.next());
|
707
|
-
assertEquals("ABCDE", i2.next());
|
708
|
-
assertEquals("abcde", i2.next());
|
709
|
-
assertEquals(new BigDecimal("0"), i2.next());
|
710
|
-
assertEquals(new BigDecimal("123.45"), i2.next());
|
711
|
-
assertEquals(toTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
712
|
-
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
713
|
-
}
|
714
|
-
{
|
715
|
-
Iterator<Object> i2 = i1.next().iterator();
|
716
|
-
assertEquals("A002", i2.next());
|
717
|
-
assertEquals("AB", i2.next());
|
718
|
-
assertEquals("abcdef", i2.next());
|
719
|
-
assertEquals(new BigDecimal("-9999"), i2.next());
|
720
|
-
assertEquals(new BigDecimal("-99999999.99"), i2.next());
|
721
|
-
assertEquals(toTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
722
|
-
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
723
|
-
}
|
724
|
-
{
|
725
|
-
Iterator<Object> i2 = i1.next().iterator();
|
726
|
-
assertEquals("A003", i2.next());
|
727
|
-
assertEquals(null, i2.next());
|
728
|
-
assertEquals(null, i2.next());
|
729
|
-
assertEquals(null, i2.next());
|
730
|
-
assertEquals(null, i2.next());
|
731
|
-
assertEquals(null, i2.next());
|
732
|
-
assertEquals(null, i2.next());
|
733
|
-
}
|
734
|
-
}
|
735
|
-
|
736
|
-
private void assertTableEmpty(String table) throws Exception
|
737
|
-
{
|
738
|
-
if (!enabled) {
|
739
|
-
return;
|
740
|
-
}
|
741
|
-
|
742
|
-
List<List<Object>> rows = select(table);
|
743
|
-
assertEquals(0, rows.size());
|
744
|
-
}
|
745
|
-
|
746
|
-
private void assertGeneratedTable1(String table) throws Exception
|
747
|
-
{
|
748
|
-
if (!enabled) {
|
749
|
-
return;
|
750
|
-
}
|
751
|
-
|
752
|
-
// datetime of UTC will be inserted by embulk.
|
753
|
-
// datetime of default timezone will be selected by JDBC.
|
754
|
-
TimeZone timeZone = TimeZone.getDefault();
|
755
|
-
List<List<Object>> rows = select(table);
|
756
|
-
|
757
|
-
/*
|
758
|
-
A001,ABCDE,abcde,0,123.45,2015/03/05,2015/03/05 12:34:56
|
759
|
-
A002,AB,abcdef,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
760
|
-
A003,,,,,,
|
761
|
-
*/
|
762
|
-
|
763
|
-
assertEquals(3, rows.size());
|
764
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
765
|
-
{
|
766
|
-
Iterator<Object> i2 = i1.next().iterator();
|
767
|
-
assertEquals("A001", i2.next());
|
768
|
-
assertEquals("ABCDE", i2.next());
|
769
|
-
assertEquals("abcde", i2.next());
|
770
|
-
assertEquals(new BigDecimal("0"), i2.next());
|
771
|
-
assertEquals("123.45", i2.next());
|
772
|
-
assertEquals(toOracleTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
773
|
-
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
774
|
-
}
|
775
|
-
{
|
776
|
-
Iterator<Object> i2 = i1.next().iterator();
|
777
|
-
assertEquals("A002", i2.next());
|
778
|
-
assertEquals("AB", i2.next());
|
779
|
-
assertEquals("abcdef", i2.next());
|
780
|
-
assertEquals(new BigDecimal("-9999"), i2.next());
|
781
|
-
assertEquals("-99999999.99", i2.next());
|
782
|
-
assertEquals(toOracleTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
783
|
-
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
784
|
-
}
|
785
|
-
{
|
786
|
-
Iterator<Object> i2 = i1.next().iterator();
|
787
|
-
assertEquals("A003", i2.next());
|
788
|
-
assertEquals(null, i2.next());
|
789
|
-
assertEquals(null, i2.next());
|
790
|
-
assertEquals(null, i2.next());
|
791
|
-
assertEquals(null, i2.next());
|
792
|
-
assertEquals(null, i2.next());
|
793
|
-
assertEquals(null, i2.next());
|
794
|
-
}
|
795
|
-
}
|
796
|
-
|
797
|
-
private void assertGeneratedTable2(String table) throws Exception
|
798
|
-
{
|
799
|
-
if (!enabled) {
|
800
|
-
return;
|
801
|
-
}
|
802
|
-
|
803
|
-
// datetime of UTC will be inserted by embulk.
|
804
|
-
// datetime of default timezone will be selected by JDBC.
|
805
|
-
TimeZone timeZone = TimeZone.getDefault();
|
806
|
-
List<List<Object>> rows = select(table);
|
807
|
-
|
808
|
-
/*
|
809
|
-
A001,ABCDE,abcde,0,123.45,2015/03/05,2015/03/05 12:34:56
|
810
|
-
A002,AB,abcdef,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
811
|
-
A003,,,,,,
|
812
|
-
*/
|
813
|
-
|
814
|
-
assertEquals(3, rows.size());
|
815
|
-
Iterator<List<Object>> i1 = rows.iterator();
|
816
|
-
{
|
817
|
-
Iterator<Object> i2 = i1.next().iterator();
|
818
|
-
assertEquals("A001", i2.next());
|
819
|
-
assertEquals("ABCDE", i2.next());
|
820
|
-
assertEquals("abcde", i2.next());
|
821
|
-
assertEquals(new BigDecimal("0"), i2.next());
|
822
|
-
assertEquals(new BigDecimal("123.45"), i2.next());
|
823
|
-
assertEquals(toTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
824
|
-
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
825
|
-
}
|
826
|
-
{
|
827
|
-
Iterator<Object> i2 = i1.next().iterator();
|
828
|
-
assertEquals("A002", i2.next());
|
829
|
-
assertEquals("AB", i2.next());
|
830
|
-
assertEquals("abcdef", i2.next());
|
831
|
-
assertEquals(new BigDecimal("-9999"), i2.next());
|
832
|
-
assertEquals(new BigDecimal("-99999999.99"), i2.next());
|
833
|
-
assertEquals(toTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
834
|
-
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
835
|
-
}
|
836
|
-
{
|
837
|
-
Iterator<Object> i2 = i1.next().iterator();
|
838
|
-
assertEquals("A003", i2.next());
|
839
|
-
assertEquals(null, i2.next());
|
840
|
-
assertEquals(null, i2.next());
|
841
|
-
assertEquals(null, i2.next());
|
842
|
-
assertEquals(null, i2.next());
|
843
|
-
assertEquals(null, i2.next());
|
844
|
-
assertEquals(null, i2.next());
|
845
|
-
}
|
846
|
-
}
|
847
|
-
|
848
|
-
@Override
|
849
|
-
protected Object getValue(ResultSet resultSet, int index) throws SQLException
|
850
|
-
{
|
851
|
-
if (resultSet.getMetaData().getColumnTypeName(index).equals("CLOB")) {
|
852
|
-
return resultSet.getString(index);
|
853
|
-
}
|
854
|
-
return super.getValue(resultSet, index);
|
855
|
-
}
|
856
|
-
|
857
|
-
|
858
|
-
private Timestamp toTimestamp(String s, TimeZone timeZone)
|
859
|
-
{
|
860
|
-
for (String formatString : new String[]{"yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd"}) {
|
861
|
-
DateFormat dateFormat = new SimpleDateFormat(formatString);
|
862
|
-
dateFormat.setTimeZone(timeZone);
|
863
|
-
try {
|
864
|
-
Date date = dateFormat.parse(s);
|
865
|
-
return new Timestamp(date.getTime());
|
866
|
-
} catch (ParseException e) {
|
867
|
-
// NOP
|
868
|
-
}
|
869
|
-
}
|
870
|
-
throw new IllegalArgumentException(s);
|
871
|
-
}
|
872
|
-
|
873
|
-
private Object toOracleTimestamp(String s, TimeZone timeZone) throws Exception
|
874
|
-
{
|
875
|
-
Class<?> timestampClass = Class.forName("oracle.sql.TIMESTAMP");
|
876
|
-
Constructor<?> constructor = timestampClass.getConstructor(Timestamp.class);
|
877
|
-
return constructor.newInstance(toTimestamp(s, timeZone));
|
878
|
-
}
|
879
|
-
|
880
|
-
@Override
|
881
|
-
protected Connection connect() throws SQLException
|
882
|
-
{
|
883
|
-
return DriverManager.getConnection(String.format(ENGLISH, "jdbc:oracle:thin:@%s:%d:%s", getHost(), getPort(), getDatabase()),
|
884
|
-
getUser(), getPassword());
|
885
|
-
}
|
886
|
-
|
887
|
-
}
|