embulk-output-oracle 0.6.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29b0a0f62c43923ecb8fced2310c707fa9549dee
4
- data.tar.gz: 0a4b933f2770fb1db850232a3e3b871f29b24890
3
+ metadata.gz: 93819131e319fc21dfc222a8cc210314c6090b11
4
+ data.tar.gz: 95c2ce5f6e6c6b76ece685fdfa7db3ab72462e10
5
5
  SHA512:
6
- metadata.gz: 1ea9df3f2e4533a3a486ffea7fce1da41a1ca87a4af0a378db09b02a18c4a06d886093a36867864af0c0dc6c8363c85b7585d85c472c5a3c738c843c33ac8dc8
7
- data.tar.gz: 1a7b88ceaa62d485f351c9267ef9f3061f65bebf57edbb0ddc74aed315bad72fa10c4ec04e20e514965978f4999a7126fd918f5c0513406f660b7a22abea9b4b
6
+ metadata.gz: 7103236d7c51629469c5940c4b39a197c48ff57f46f63ca0b8a21e2dcdfe725c4bb3efb20706bba400af470ef0fc1670c5d4eaac0354aaa49efc08262b260bc0
7
+ data.tar.gz: 152fae8051856d856bc542e544dcb916c1307d761454998f7a26d1b31df88c1e922c02a86a3478202a37ecc9c5758476336a90af22f44fbdba3a4d3a01e04b48
@@ -153,21 +153,13 @@ public class DirectBatchInsert implements BatchInsert
153
153
  rowSize += column.getDataSize();
154
154
  }
155
155
 
156
- TableDefinition tableDefinition = new TableDefinition(quoteIdentifierString(schema), quoteIdentifierString(loadTable), columns);
156
+ TableDefinition tableDefinition = new TableDefinition(schema, loadTable, columns);
157
157
  ociKey = Arrays.asList(database, user, loadTable);
158
158
  ociManager.open(ociKey, database, user, password, tableDefinition);
159
159
 
160
160
  buffer = new RowBuffer(tableDefinition, Math.max(batchSize / rowSize, 8));
161
161
  }
162
162
 
163
- private String quoteIdentifierString(String s)
164
- {
165
- if (s == null) {
166
- return null;
167
- }
168
- return "\"" + s + "\"";
169
- }
170
-
171
163
  @Override
172
164
  public int getBatchWeight()
173
165
  {
@@ -15,7 +15,6 @@ public interface OCI
15
15
  static short OCI_NO_DATA = 100;
16
16
  static short OCI_CONTINUE = -24200;
17
17
 
18
-
19
18
  static int OCI_THREADED = 1;
20
19
  static int OCI_OBJECT = 2;
21
20
 
@@ -36,13 +35,14 @@ public interface OCI
36
35
  static int OCI_ATTR_NUM_ROWS = 81;
37
36
  static int OCI_ATTR_NUM_COLS = 102;
38
37
  static int OCI_ATTR_LIST_COLUMNS = 103;
38
+ static int OCI_ATTR_DIRPATH_NO_INDEX_ERRORS = 2013;
39
39
 
40
40
  static int OCI_DTYPE_PARAM = 53;
41
41
 
42
42
  static byte OCI_DIRPATH_COL_COMPLETE = 0;
43
43
 
44
- static int SQLT_CHR = 1;
45
- static int SQLT_INT = 3;
44
+ static short SQLT_CHR = 1;
45
+ static short SQLT_INT = 3;
46
46
 
47
47
  short OCIErrorGet(Pointer hndlp,
48
48
  @u_int32_t int recordno,
@@ -129,4 +129,4 @@ public interface OCI
129
129
  short OCIDirPathFinish(Pointer dpctx, Pointer errhp);
130
130
 
131
131
  short OCIDirPathAbort(Pointer dpctx, Pointer errhp);
132
- }
132
+ }
@@ -54,8 +54,8 @@ public class OCIManager
54
54
  ociAndCounter.counter--;
55
55
  if (ociAndCounter.counter == 0) {
56
56
  logger.info(String.format("OCI : close for %s.", key));
57
- ociAndCounter.oci.close();
58
57
  ociAndCounters.remove(key);
58
+ ociAndCounter.oci.close();
59
59
  }
60
60
  }
61
61
  }
@@ -24,7 +24,6 @@ public class OCIWrapper
24
24
  private final Charset systemCharset;
25
25
  private Pointer envHandle;
26
26
  private Pointer errHandle;
27
- private Pointer svcHandlePointer;
28
27
  private Pointer svcHandle;
29
28
  private Pointer dpHandle;
30
29
  private Pointer dpcaHandle;
@@ -95,7 +94,7 @@ public class OCIWrapper
95
94
  errHandle = errHandlePointer.getPointer(0);
96
95
 
97
96
  // service context
98
- svcHandlePointer = createPointerPointer();
97
+ Pointer svcHandlePointer = createPointerPointer();
99
98
  check("OCIHandleAlloc(OCI_HTYPE_SVCCTX)", oci.OCIHandleAlloc(
100
99
  envHandle,
101
100
  svcHandlePointer,
@@ -142,8 +141,17 @@ public class OCIWrapper
142
141
  errHandle));
143
142
  }
144
143
 
145
- // load table name
146
- Pointer tableName = createPointer(tableDefinition.getTableName());
144
+ Pointer cols = createPointer((short)tableDefinition.getColumnCount());
145
+ check("OCIAttrSet(OCI_ATTR_NUM_COLS)", oci.OCIAttrSet(
146
+ dpHandle,
147
+ OCI.OCI_HTYPE_DIRPATH_CTX,
148
+ cols,
149
+ (int)cols.size(),
150
+ OCI.OCI_ATTR_NUM_COLS,
151
+ errHandle));
152
+
153
+ // load table name (case sensitive)
154
+ Pointer tableName = createPointer("\"" + tableDefinition.getTableName() + "\"");
147
155
  check("OCIAttrSet(OCI_ATTR_NAME)", oci.OCIAttrSet(
148
156
  dpHandle,
149
157
  OCI.OCI_HTYPE_DIRPATH_CTX,
@@ -152,13 +160,13 @@ public class OCIWrapper
152
160
  , OCI.OCI_ATTR_NAME,
153
161
  errHandle));
154
162
 
155
- Pointer cols = createPointer((short)tableDefinition.getColumnCount());
156
- check("OCIAttrSet(OCI_ATTR_NUM_COLS)", oci.OCIAttrSet(
163
+ Pointer noIndexErrors = createPointer((byte)1);
164
+ check("OCIAttrSet(OCI_ATTR_DIRPATH_NO_INDEX_ERRORS)", oci.OCIAttrSet(
157
165
  dpHandle,
158
166
  OCI.OCI_HTYPE_DIRPATH_CTX,
159
- cols,
160
- (int)cols.size(),
161
- OCI.OCI_ATTR_NUM_COLS,
167
+ noIndexErrors,
168
+ (int)noIndexErrors.size(),
169
+ OCI.OCI_ATTR_DIRPATH_NO_INDEX_ERRORS,
162
170
  errHandle));
163
171
 
164
172
  Pointer columnsPointer = createPointerPointer();
@@ -352,10 +360,12 @@ public class OCIWrapper
352
360
  committedOrRollbacked = true;
353
361
  logger.info("OCI : start to commit.");
354
362
 
355
- check("OCIDirPathFinish", oci.OCIDirPathFinish(dpHandle, errHandle));
356
-
357
- check("OCILogoff", oci.OCILogoff(svcHandle, errHandle));
358
- svcHandle = null;
363
+ try {
364
+ check("OCIDirPathFinish", oci.OCIDirPathFinish(dpHandle, errHandle));
365
+ } finally {
366
+ check("OCILogoff", oci.OCILogoff(svcHandle, errHandle));
367
+ svcHandle = null;
368
+ }
359
369
  }
360
370
 
361
371
  public void rollback() throws SQLException
@@ -363,10 +373,12 @@ public class OCIWrapper
363
373
  committedOrRollbacked = true;
364
374
  logger.info("OCI : start to rollback.");
365
375
 
366
- check("OCIDirPathAbort", oci.OCIDirPathAbort(dpHandle, errHandle));
367
-
368
- check("OCILogoff", oci.OCILogoff(svcHandle, errHandle));
369
- svcHandle = null;
376
+ try {
377
+ check("OCIDirPathAbort", oci.OCIDirPathAbort(dpHandle, errHandle));
378
+ } finally {
379
+ check("OCILogoff", oci.OCILogoff(svcHandle, errHandle));
380
+ svcHandle = null;
381
+ }
370
382
  }
371
383
 
372
384
  public void close() throws SQLException
@@ -413,6 +425,13 @@ public class OCIWrapper
413
425
  return Pointer.wrap(Runtime.getSystemRuntime(), ByteBuffer.wrap(s.getBytes(systemCharset)));
414
426
  }
415
427
 
428
+ private Pointer createPointer(byte n)
429
+ {
430
+ Pointer pointer = new ArrayMemoryIO(Runtime.getSystemRuntime(), 1);
431
+ pointer.putByte(0, n);
432
+ return pointer;
433
+ }
434
+
416
435
  private Pointer createPointer(short n)
417
436
  {
418
437
  Pointer pointer = new ArrayMemoryIO(Runtime.getSystemRuntime(), 2);
@@ -70,8 +70,8 @@ public class RowBuffer
70
70
 
71
71
  ByteBuffer bytes = charset.encode(value);
72
72
  int length = bytes.remaining();
73
- if (length > 65535) {
74
- throw new SQLException(String.format("byte count of string is too large (max : 65535, actual : %d).", length));
73
+ if (length > Short.MAX_VALUE) {
74
+ throw new SQLException(String.format("byte count of string is too large (max : %d, actual : %d).", Short.MAX_VALUE, length));
75
75
  }
76
76
  if (length > column.getDataSize()) {
77
77
  throw new SQLException(String.format("byte count of string is too large for column \"%s\" (max : %d, actual : %d).",
@@ -175,6 +175,12 @@ public class OracleOutputPluginTest
175
175
  invoke(test12c, "testInsertDirect");
176
176
  }
177
177
 
178
+ @Test
179
+ public void testInsertDirectDuplicate() throws Exception
180
+ {
181
+ invoke(test12c, "testInsertDirectDuplicate");
182
+ }
183
+
178
184
  @Test
179
185
  public void testInsertDirectCreate() throws Exception
180
186
  {
@@ -199,6 +205,24 @@ public class OracleOutputPluginTest
199
205
  invoke(test12c, "testInsertDirectOCIMethod");
200
206
  }
201
207
 
208
+ @Test
209
+ public void testInsertDirectOCIMethodDuplicate() throws Exception
210
+ {
211
+ invoke(test12c, "testInsertDirectOCIMethodDuplicate");
212
+ }
213
+
214
+ @Test
215
+ public void testInsertDirectOCIMethodMultibyte() throws Exception
216
+ {
217
+ invoke(test12c, "testInsertDirectOCIMethodMultibyte");
218
+ }
219
+
220
+ @Test
221
+ public void testInsertDirectOCIMethodMultibyteDuplicate() throws Exception
222
+ {
223
+ invoke(test12c, "testInsertDirectOCIMethodMultibyteDuplicate");
224
+ }
225
+
202
226
  @Test
203
227
  public void testInsertDirectOCIMethodSplit() throws Exception
204
228
  {
@@ -211,6 +235,24 @@ public class OracleOutputPluginTest
211
235
  invoke(test12c, "testUrl");
212
236
  }
213
237
 
238
+ @Test
239
+ public void testLowerTable() throws Exception
240
+ {
241
+ invoke(test12c, "testLowerTable");
242
+ }
243
+
244
+ @Test
245
+ public void testLowerColumn() throws Exception
246
+ {
247
+ invoke(test12c, "testLowerColumn");
248
+ }
249
+
250
+ @Test
251
+ public void testLowerColumnOptions() throws Exception
252
+ {
253
+ invoke(test12c, "testLowerColumnOptions");
254
+ }
255
+
214
256
  @Test
215
257
  public void testReplace() throws Exception
216
258
  {
@@ -1,6 +1,7 @@
1
1
  package org.embulk.output.oracle;
2
2
 
3
3
  import static org.junit.Assert.assertEquals;
4
+ import static org.junit.Assert.fail;
4
5
 
5
6
  import java.io.File;
6
7
  import java.lang.reflect.Constructor;
@@ -147,6 +148,22 @@ public class OracleOutputPluginTestImpl extends AbstractJdbcOutputPluginTest
147
148
  assertTable(table);
148
149
  }
149
150
 
151
+ public void testInsertDirectDuplicate() throws Exception
152
+ {
153
+ String table = "TEST1";
154
+
155
+ dropTable(table);
156
+ createTable(table);
157
+ insertRecord(table, "A002");
158
+
159
+ try {
160
+ run("/oracle/yml/test-insert-direct.yml");
161
+ fail("Exception expected.");
162
+ } catch (Exception e) {
163
+ System.out.println(e);
164
+ }
165
+ }
166
+
150
167
  public void testInsertDirectEmpty() throws Exception
151
168
  {
152
169
  String table = "TEST1";
@@ -195,6 +212,50 @@ public class OracleOutputPluginTestImpl extends AbstractJdbcOutputPluginTest
195
212
  assertTable(table);
196
213
  }
197
214
 
215
+ public void testInsertDirectOCIMethodDuplicate() throws Exception
216
+ {
217
+ String table = "TEST1";
218
+
219
+ dropTable(table);
220
+ createTable(table);
221
+ insertRecord(table, "A002");
222
+
223
+ try {
224
+ run("/oracle/yml/test-insert-direct-oci-method.yml");
225
+ fail("Exception expected.");
226
+ } catch (Exception e) {
227
+ System.out.println(e);
228
+ }
229
+ }
230
+
231
+ public void testInsertDirectOCIMethodMultibyte() throws Exception
232
+ {
233
+ String table = "TEST1";
234
+
235
+ dropTable(table);
236
+ createTable(table);
237
+
238
+ run("/oracle/yml/test-insert-direct-oci-method-multibyte.yml");
239
+
240
+ assertTable(table);
241
+ }
242
+
243
+ public void testInsertDirectOCIMethodMultibyteDuplicate() throws Exception
244
+ {
245
+ String table = "TEST1";
246
+
247
+ dropTable(table);
248
+ createTable(table);
249
+ insertRecord(table, "A002");
250
+
251
+ try {
252
+ run("/oracle/yml/test-insert-direct-oci-method-multibyte.yml");
253
+ fail("Exception expected.");
254
+ } catch (Exception e) {
255
+ System.out.println(e);
256
+ }
257
+ }
258
+
198
259
  public void testInsertDirectOCIMethodSplit() throws Exception
199
260
  {
200
261
  String table = "TEST1";
@@ -219,6 +280,42 @@ public class OracleOutputPluginTestImpl extends AbstractJdbcOutputPluginTest
219
280
  assertTable(table);
220
281
  }
221
282
 
283
+ public void testLowerTable() throws Exception
284
+ {
285
+ String table = "TEST1";
286
+
287
+ dropTable(table);
288
+ createTable(table);
289
+
290
+ run("/oracle/yml/test-lower-table.yml");
291
+
292
+ assertTable(table);
293
+ }
294
+
295
+ public void testLowerColumn() throws Exception
296
+ {
297
+ String table = "TEST1";
298
+
299
+ dropTable(table);
300
+ createTable(table);
301
+
302
+ run("/oracle/yml/test-lower-column.yml");
303
+
304
+ assertTable(table);
305
+ }
306
+
307
+ public void testLowerColumnOptions() throws Exception
308
+ {
309
+ String table = "TEST1";
310
+
311
+ dropTable(table);
312
+ createTable(table);
313
+
314
+ run("/oracle/yml/test-lower-column-options.yml");
315
+
316
+ assertTable(table);
317
+ }
318
+
222
319
  public void testReplace() throws Exception
223
320
  {
224
321
  String table = "TEST1";
@@ -316,7 +413,12 @@ public class OracleOutputPluginTestImpl extends AbstractJdbcOutputPluginTest
316
413
 
317
414
  private void insertRecord(String table) throws SQLException
318
415
  {
319
- executeSQL(String.format("INSERT INTO %s VALUES('9999', NULL, NULL, NULL, NULL, NULL, NULL)", table));
416
+ insertRecord(table, "9999");
417
+ }
418
+
419
+ private void insertRecord(String table, String id) throws SQLException
420
+ {
421
+ executeSQL(String.format("INSERT INTO %s VALUES('%s', NULL, NULL, NULL, NULL, NULL, NULL)", table, id));
320
422
  }
321
423
 
322
424
  private void assertTable(String table) throws Exception
@@ -0,0 +1,29 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/oracle/data/test1/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: ID, type: string}
12
+ - {name: VARCHAR2_ITEM, type: string}
13
+ - {name: NVARCHAR2_ITEM, type: string}
14
+ - {name: INTEGER_ITEM, type: long}
15
+ - {name: NUMBER_ITEM, type: string}
16
+ - {name: DATE_ITEM, type: timestamp, format: '%Y/%m/%d'}
17
+ - {name: TIMESTAMP_ITEM, type: timestamp, format: '%Y/%m/%d %H:%M:%S'}
18
+ out:
19
+ type: oracle
20
+ host: localhost
21
+ database: TESTDB
22
+ user: TEST_USER
23
+ password: test_pw
24
+ table: TEST1
25
+ mode: insert_direct
26
+ insert_method: oci
27
+ column_options:
28
+ INTEGER_ITEM: {value_type: pass}
29
+ #driver_path: driver/ojdbc7.jar
@@ -0,0 +1,29 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/oracle/data/test1/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: varchar2_item, type: string}
13
+ - {name: nvarchar2_item, type: string}
14
+ - {name: integer_item, type: long}
15
+ - {name: number_item, type: string}
16
+ - {name: date_item, type: string}
17
+ - {name: timestamp_item, type: string}
18
+ out:
19
+ type: oracle
20
+ host: localhost
21
+ database: TESTDB
22
+ user: TEST_USER
23
+ password: test_pw
24
+ table: TEST1
25
+ mode: insert_direct
26
+ column_options:
27
+ date_item: {value_type: pass}
28
+ timestamp_item: {value_type: pass}
29
+ #driver_path: driver/ojdbc7.jar
@@ -0,0 +1,26 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/oracle/data/test1/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: id, type: string}
12
+ - {name: varchar2_item, type: string}
13
+ - {name: nvarchar2_item, type: string}
14
+ - {name: integer_item, type: long}
15
+ - {name: number_item, type: string}
16
+ - {name: date_item, type: timestamp, format: '%Y/%m/%d'}
17
+ - {name: timestamp_item, type: timestamp, format: '%Y/%m/%d %H:%M:%S'}
18
+ out:
19
+ type: oracle
20
+ host: localhost
21
+ database: TESTDB
22
+ user: TEST_USER
23
+ password: test_pw
24
+ table: TEST1
25
+ mode: insert_direct
26
+ #driver_path: driver/ojdbc7.jar
@@ -0,0 +1,26 @@
1
+ in:
2
+ type: file
3
+ path_prefix: '/oracle/data/test1/test1.csv'
4
+ parser:
5
+ charset: UTF-8
6
+ newline: CRLF
7
+ type: csv
8
+ delimiter: ','
9
+ quote: ''
10
+ columns:
11
+ - {name: ID, type: string}
12
+ - {name: VARCHAR2_ITEM, type: string}
13
+ - {name: NVARCHAR2_ITEM, type: string}
14
+ - {name: INTEGER_ITEM, type: long}
15
+ - {name: NUMBER_ITEM, type: string}
16
+ - {name: DATE_ITEM, type: timestamp, format: '%Y/%m/%d'}
17
+ - {name: TIMESTAMP_ITEM, type: timestamp, format: '%Y/%m/%d %H:%M:%S'}
18
+ out:
19
+ type: oracle
20
+ host: localhost
21
+ database: TESTDB
22
+ user: TEST_USER
23
+ password: test_pw
24
+ table: test1
25
+ mode: insert_direct
26
+ #driver_path: driver/ojdbc7.jar
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-oracle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.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: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -40,11 +40,15 @@ files:
40
40
  - src/test/resources/oracle/data/test1/test1.csv
41
41
  - src/test/resources/oracle/yml/test-insert-direct-direct-method.yml
42
42
  - src/test/resources/oracle/yml/test-insert-direct-empty.yml
43
+ - src/test/resources/oracle/yml/test-insert-direct-oci-method-multibyte.yml
43
44
  - src/test/resources/oracle/yml/test-insert-direct-oci-method-split.yml
44
45
  - src/test/resources/oracle/yml/test-insert-direct-oci-method.yml
45
46
  - src/test/resources/oracle/yml/test-insert-direct.yml
46
47
  - src/test/resources/oracle/yml/test-insert-empty.yml
47
48
  - src/test/resources/oracle/yml/test-insert.yml
49
+ - src/test/resources/oracle/yml/test-lower-column-options.yml
50
+ - src/test/resources/oracle/yml/test-lower-column.yml
51
+ - src/test/resources/oracle/yml/test-lower-table.yml
48
52
  - src/test/resources/oracle/yml/test-replace-empty.yml
49
53
  - src/test/resources/oracle/yml/test-replace-long-name-multibyte.yml
50
54
  - src/test/resources/oracle/yml/test-replace-long-name.yml
@@ -54,8 +58,8 @@ files:
54
58
  - src/test/resources/oracle/yml/test-truncate-insert-oci-method.yml
55
59
  - src/test/resources/oracle/yml/test-truncate-insert.yml
56
60
  - src/test/resources/oracle/yml/test-url.yml
57
- - classpath/embulk-output-jdbc-0.6.0.jar
58
- - classpath/embulk-output-oracle-0.6.0.jar
61
+ - classpath/embulk-output-jdbc-0.6.1.jar
62
+ - classpath/embulk-output-oracle-0.6.1.jar
59
63
  homepage: https://github.com/embulk/embulk-output-jdbc
60
64
  licenses:
61
65
  - Apache 2.0