embulk-output-oracle 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f22f18309d604502073834ef9bcac39ba1c7ed2
4
- data.tar.gz: f4e47f7c177a3f8d99c0a6ebbc8eb7e3d5882417
3
+ metadata.gz: 1c196893bc6c5cd54b0fdd6933634de04145b5c2
4
+ data.tar.gz: 433b11005ff3c74efbfda08efe789e473634a15a
5
5
  SHA512:
6
- metadata.gz: f8791a70edae2c6af65682b2e96fb6186563509f7eff0d1c952d6e19b641e663e1f64624f4f57d441d4dc3d8efd8838d0006bc75c537b386c51fae3252e2ebdc
7
- data.tar.gz: 713c24da25c5b10dcb47589ec5aa690ea6f64643961f3bf3273eed14bed835c23dec84e8c352bc3fcce04555c4ec00432334b850143fd53ec4f4861708760ecb
6
+ metadata.gz: d4f361b8d4507f0993664aa40be3ee8411705148c2161de3bb172d8dc2b2e6b2ed928dbb106aa20b80a6ade4c81887cb2efd183be19b8af807373fa20d804a6b
7
+ data.tar.gz: 59614a59bb30a5c2f0a5b1d900991e1bdb6dd692b210bd4972cde255b8f40322a621becf9175b6f19c4f909ac63d56a8aaa74d0ebca0d575c1f9e59ba6408e6a
data/README.md CHANGED
@@ -5,8 +5,8 @@ Oracle output plugins for Embulk loads records to Oracle.
5
5
  ## Overview
6
6
 
7
7
  * **Plugin type**: output
8
- * **Load all or nothing**: depnds on the mode. see bellow.
9
- * **Resume supported**: depnds on the mode. see bellow.
8
+ * **Load all or nothing**: depnds on the mode. see below.
9
+ * **Resume supported**: depnds on the mode. see below.
10
10
 
11
11
  ## Configuration
12
12
 
@@ -19,7 +19,7 @@ Oracle output plugins for Embulk loads records to Oracle.
19
19
  - **url**: URL of the JDBC connection (string, optional)
20
20
  - **table**: destination table name (string, required)
21
21
  - **options**: extra connection properties (hash, default: {})
22
- - **mode**: "insert", "insert_direct", "truncate_insert", or "replace". See bellow. (string, required)
22
+ - **mode**: "insert", "insert_direct", "truncate_insert", or "replace". See below. (string, required)
23
23
  - **insert_method**: see below
24
24
  - **batch_size**: size of a single batch insert (integer, default: 16777216)
25
25
  - **default_timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp into a SQL string. This default_timezone option is used to control the timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
@@ -48,13 +48,13 @@ Oracle output plugins for Embulk loads records to Oracle.
48
48
  * Transactional: Yes.
49
49
  * Resumable: No.
50
50
 
51
- ### Insert modes
51
+ ### Insert methods
52
52
 
53
53
  insert_method supports three options.
54
54
 
55
55
  "normal" means normal insert (default). It requires Oracle JDBC driver.
56
56
 
57
- "direct" means direct path insert. It is faster than 'normal.
57
+ "direct" means direct path insert. It is faster than "normal".
58
58
  It requires Oracle JDBC driver too, but the version 12 driver doesn't work (the version 11 driver works).
59
59
 
60
60
  "oci" means direct path insert using OCI(Oracle Call Interface). It is fastest.
data/build.gradle CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  dependencies {
4
4
  compile project(':embulk-output-jdbc')
5
- testCompile 'org.embulk:embulk-standards:0.8.0'
5
+ testCompile 'org.embulk:embulk-standards:0.8.8'
6
6
  testCompile files('../embulk-output-jdbc/build/classes/test/')
7
7
  }
@@ -4,8 +4,10 @@ import java.util.List;
4
4
  import java.util.Properties;
5
5
  import java.io.IOException;
6
6
  import java.sql.SQLException;
7
+
7
8
  import com.google.common.base.Optional;
8
9
  import com.google.common.collect.ImmutableSet;
10
+
9
11
  import org.embulk.config.Config;
10
12
  import org.embulk.config.ConfigDefault;
11
13
  import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
@@ -40,6 +42,10 @@ public class OracleOutputPlugin
40
42
  @ConfigDefault("null")
41
43
  public Optional<String> getDatabase();
42
44
 
45
+ @Config("schema")
46
+ @ConfigDefault("null")
47
+ public Optional<String> getSchema();
48
+
43
49
  @Config("url")
44
50
  @ConfigDefault("null")
45
51
  public Optional<String> getUrl();
@@ -117,7 +123,7 @@ public class OracleOutputPlugin
117
123
  logger.info("Connecting to {} options {}", url, props);
118
124
  props.setProperty("password", oracleTask.getPassword());
119
125
 
120
- return new OracleOutputConnector(url, props, oracleTask.getInsertMethod() == InsertMethod.direct);
126
+ return new OracleOutputConnector(url, props, oracleTask.getSchema().orNull(), oracleTask.getInsertMethod() == InsertMethod.direct);
121
127
  }
122
128
 
123
129
  @Override
@@ -131,8 +137,8 @@ public class OracleOutputPlugin
131
137
  JdbcOutputConnector connector = getConnector(task, true);
132
138
 
133
139
  if (oracleTask.getInsertMethod() == InsertMethod.oci) {
134
- OracleCharset charset;
135
- OracleCharset nationalCharset;
140
+ OracleCharset charset;
141
+ OracleCharset nationalCharset;
136
142
  try (OracleOutputConnection connection = (OracleOutputConnection)connector.connect(true)) {
137
143
  charset = connection.getOracleCharset();
138
144
  nationalCharset = connection.getOracleNationalCharset();
@@ -142,7 +148,7 @@ public class OracleOutputPlugin
142
148
  String.format("%s:%d/%s", oracleTask.getHost().get(), oracleTask.getPort(), oracleTask.getDatabase().get()),
143
149
  oracleTask.getUser(),
144
150
  oracleTask.getPassword(),
145
- oracleTask.getTable(),
151
+ oracleTask.getSchema().orNull(),
146
152
  charset,
147
153
  nationalCharset,
148
154
  oracleTask.getBatchSize());
@@ -14,6 +14,7 @@ import java.util.List;
14
14
  import org.embulk.output.jdbc.BatchInsert;
15
15
  import org.embulk.output.jdbc.JdbcColumn;
16
16
  import org.embulk.output.jdbc.JdbcSchema;
17
+ import org.embulk.output.jdbc.TimestampFormat;
17
18
  import org.embulk.output.oracle.oci.ColumnDefinition;
18
19
  import org.embulk.output.oracle.oci.OCI;
19
20
  import org.embulk.output.oracle.oci.OCIManager;
@@ -34,6 +35,7 @@ public class DirectBatchInsert implements BatchInsert
34
35
  private final String database;
35
36
  private final String user;
36
37
  private final String password;
38
+ private final String schema;
37
39
  private final OracleCharset charset;
38
40
  private final OracleCharset nationalCharset;
39
41
  private final int batchSize;
@@ -41,16 +43,18 @@ public class DirectBatchInsert implements BatchInsert
41
43
  private long totalRows;
42
44
  private int rowSize;
43
45
  private int batchWeight;
46
+ private boolean closed;
44
47
 
45
48
  private DateFormat[] formats;
46
49
 
47
50
 
48
- public DirectBatchInsert(String database, String user, String password, String table,
51
+ public DirectBatchInsert(String database, String user, String password, String schema,
49
52
  OracleCharset charset, OracleCharset nationalCharset, int batchSize)
50
53
  {
51
54
  this.database = database;
52
55
  this.user = user;
53
56
  this.password = password;
57
+ this.schema = schema;
54
58
  this.charset = charset;
55
59
  this.nationalCharset = nationalCharset;
56
60
  this.batchSize = batchSize;
@@ -149,13 +153,21 @@ public class DirectBatchInsert implements BatchInsert
149
153
  rowSize += column.getDataSize();
150
154
  }
151
155
 
152
- TableDefinition tableDefinition = new TableDefinition("\"" + loadTable + "\"", columns);
156
+ TableDefinition tableDefinition = new TableDefinition(quoteIdentifierString(schema), quoteIdentifierString(loadTable), columns);
153
157
  ociKey = Arrays.asList(database, user, loadTable);
154
158
  ociManager.open(ociKey, database, user, password, tableDefinition);
155
159
 
156
160
  buffer = new RowBuffer(tableDefinition, Math.max(batchSize / rowSize, 8));
157
161
  }
158
162
 
163
+ private String quoteIdentifierString(String s)
164
+ {
165
+ if (s == null) {
166
+ return null;
167
+ }
168
+ return "\"" + s + "\"";
169
+ }
170
+
159
171
  @Override
160
172
  public int getBatchWeight()
161
173
  {
@@ -174,7 +186,10 @@ public class DirectBatchInsert implements BatchInsert
174
186
  @Override
175
187
  public void close() throws IOException, SQLException
176
188
  {
177
- ociManager.close(ociKey);
189
+ if (!closed) {
190
+ ociManager.close(ociKey);
191
+ closed = true;
192
+ }
178
193
  }
179
194
 
180
195
  @Override
@@ -32,10 +32,10 @@ public class OracleOutputConnection
32
32
  private OracleCharset charset;
33
33
  private OracleCharset nationalCharset;
34
34
 
35
- public OracleOutputConnection(Connection connection, boolean autoCommit, boolean direct)
35
+ public OracleOutputConnection(Connection connection, String schemaName, boolean autoCommit, boolean direct)
36
36
  throws SQLException
37
37
  {
38
- super(connection, getSchema(connection));
38
+ super(connection, schemaName == null ? getSchema(connection) : schemaName);
39
39
  connection.setAutoCommit(autoCommit);
40
40
 
41
41
  this.direct = direct;
@@ -54,7 +54,10 @@ public class OracleOutputConnection
54
54
 
55
55
  @Override
56
56
  protected void setSearchPath(String schema) throws SQLException {
57
- // NOP
57
+ if (!getSchema(connection).equals(schema)) {
58
+ // Because old Oracle JDBC drivers don't support Connection#setSchema method.
59
+ connection.setSchema(schema);
60
+ }
58
61
  }
59
62
 
60
63
  @Override
@@ -12,9 +12,10 @@ public class OracleOutputConnector
12
12
  {
13
13
  private final String url;
14
14
  private final Properties properties;
15
+ private final String schemaName;
15
16
  private final boolean direct;
16
17
 
17
- public OracleOutputConnector(String url, Properties properties, boolean direct)
18
+ public OracleOutputConnector(String url, Properties properties, String schemaName, boolean direct)
18
19
  {
19
20
  try {
20
21
  Class.forName("oracle.jdbc.OracleDriver");
@@ -23,6 +24,7 @@ public class OracleOutputConnector
23
24
  }
24
25
  this.url = url;
25
26
  this.properties = properties;
27
+ this.schemaName = schemaName;
26
28
  this.direct = direct;
27
29
  }
28
30
 
@@ -36,7 +38,7 @@ public class OracleOutputConnector
36
38
  }
37
39
 
38
40
  try {
39
- OracleOutputConnection con = new OracleOutputConnection(c, autoCommit, direct);
41
+ OracleOutputConnection con = new OracleOutputConnection(c, schemaName, autoCommit, direct);
40
42
  c = null;
41
43
  return con;
42
44
 
@@ -30,6 +30,7 @@ public interface OCI
30
30
  static int OCI_ATTR_DATA_TYPE = 2;
31
31
  static int OCI_ATTR_NAME = 4;
32
32
  static int OCI_ATTR_ROW_COUNT = 9;
33
+ static int OCI_ATTR_SCHEMA_NAME = 9;
33
34
  static int OCI_ATTR_CHARSET_ID = 31;
34
35
  static int OCI_ATTR_DATEFORMAT = 75;
35
36
  static int OCI_ATTR_NUM_ROWS = 81;
@@ -131,6 +131,17 @@ public class OCIWrapper
131
131
  {
132
132
  this.tableDefinition = tableDefinition;
133
133
 
134
+ if (tableDefinition.getSchemaName() != null) {
135
+ Pointer schemaName = createPointer(tableDefinition.getSchemaName());
136
+ check("OCIAttrSet(OCI_ATTR_NAME)", oci.OCIAttrSet(
137
+ dpHandle,
138
+ OCI.OCI_HTYPE_DIRPATH_CTX,
139
+ schemaName,
140
+ (int)schemaName.size()
141
+ , OCI.OCI_ATTR_SCHEMA_NAME,
142
+ errHandle));
143
+ }
144
+
134
145
  // load table name
135
146
  Pointer tableName = createPointer(tableDefinition.getTableName());
136
147
  check("OCIAttrSet(OCI_ATTR_NAME)", oci.OCIAttrSet(
@@ -398,7 +409,8 @@ public class OCIWrapper
398
409
 
399
410
  private Pointer createPointer(String s)
400
411
  {
401
- return Pointer.wrap(Runtime.getSystemRuntime(), ByteBuffer.wrap(s.getBytes()));
412
+ // not database charset, but system charset of client
413
+ return Pointer.wrap(Runtime.getSystemRuntime(), ByteBuffer.wrap(s.getBytes(systemCharset)));
402
414
  }
403
415
 
404
416
  private Pointer createPointer(short n)
@@ -4,33 +4,40 @@ import java.util.List;
4
4
 
5
5
  public class TableDefinition
6
6
  {
7
+ private final String schemaName;
7
8
  private final String tableName;
8
9
  private final ColumnDefinition[] columns;
9
10
 
10
11
 
11
- public TableDefinition(String tableName, ColumnDefinition... columns)
12
+ public TableDefinition(String schemaName, String tableName, ColumnDefinition... columns)
12
13
  {
14
+ this.schemaName = schemaName;
13
15
  this.tableName = tableName;
14
16
  this.columns = columns;
15
17
  }
16
18
 
17
- public TableDefinition(String tableName, List<ColumnDefinition> columns)
19
+ public TableDefinition(String schemaName, String tableName, List<ColumnDefinition> columns)
18
20
  {
19
- this(tableName, columns.toArray(new ColumnDefinition[columns.size()]));
21
+ this(schemaName, tableName, columns.toArray(new ColumnDefinition[columns.size()]));
22
+ }
23
+
24
+ public String getSchemaName()
25
+ {
26
+ return schemaName;
20
27
  }
21
28
 
22
29
  public String getTableName()
23
30
  {
24
- return tableName;
31
+ return tableName;
25
32
  }
26
33
 
27
34
  public int getColumnCount()
28
35
  {
29
- return columns.length;
36
+ return columns.length;
30
37
  }
31
38
 
32
39
  public ColumnDefinition getColumn(int index)
33
40
  {
34
- return columns[index];
41
+ return columns[index];
35
42
  }
36
43
  }
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.5.0
4
+ version: 0.5.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-01-15 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -26,7 +26,6 @@ files:
26
26
  - src/main/java/org/embulk/output/oracle/OracleCharset.java
27
27
  - src/main/java/org/embulk/output/oracle/OracleOutputConnection.java
28
28
  - src/main/java/org/embulk/output/oracle/OracleOutputConnector.java
29
- - src/main/java/org/embulk/output/oracle/TimestampFormat.java
30
29
  - src/main/java/org/embulk/output/oracle/oci/ColumnDefinition.java
31
30
  - src/main/java/org/embulk/output/oracle/oci/OCI.java
32
31
  - src/main/java/org/embulk/output/oracle/oci/OCIManager.java
@@ -38,7 +37,6 @@ files:
38
37
  - src/test/java/org/embulk/input/filesplit/PartialFileInputStream.java
39
38
  - src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java
40
39
  - src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java
41
- - src/test/java/org/embulk/output/oracle/TimestampFormatTest.java
42
40
  - src/test/resources/oracle/data/test1/test1.csv
43
41
  - src/test/resources/oracle/yml/test-insert-direct-direct-method.yml
44
42
  - src/test/resources/oracle/yml/test-insert-direct-empty.yml
@@ -56,8 +54,8 @@ files:
56
54
  - src/test/resources/oracle/yml/test-truncate-insert-oci-method.yml
57
55
  - src/test/resources/oracle/yml/test-truncate-insert.yml
58
56
  - src/test/resources/oracle/yml/test-url.yml
59
- - classpath/embulk-output-jdbc-0.5.0.jar
60
- - classpath/embulk-output-oracle-0.5.0.jar
57
+ - classpath/embulk-output-jdbc-0.5.1.jar
58
+ - classpath/embulk-output-oracle-0.5.1.jar
61
59
  homepage: https://github.com/embulk/embulk-output-jdbc
62
60
  licenses:
63
61
  - Apache 2.0
@@ -1,37 +0,0 @@
1
- package org.embulk.output.oracle;
2
-
3
- import java.sql.Timestamp;
4
- import java.text.FieldPosition;
5
- import java.text.SimpleDateFormat;
6
- import java.util.Date;
7
-
8
-
9
- public class TimestampFormat extends SimpleDateFormat
10
- {
11
-
12
- private final int scale;
13
-
14
- public TimestampFormat(String pattern, int scale)
15
- {
16
- super(pattern);
17
-
18
- this.scale = scale;
19
- }
20
-
21
- @Override
22
- public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
23
- {
24
- StringBuffer buffer = super.format(date, toAppendTo, pos);
25
- if (scale > 0) {
26
- buffer.append('.');
27
- String nanos = Integer.toString(((Timestamp)date).getNanos());
28
- int zeros = Math.min(scale, 9 - nanos.length());
29
- for (int i = 0; i < zeros; i++) {
30
- buffer.append('0');
31
- }
32
- buffer.append(nanos.substring(0, scale - zeros));
33
- }
34
- return buffer;
35
- }
36
-
37
- }
@@ -1,57 +0,0 @@
1
- package org.embulk.output.oracle;
2
-
3
- import java.sql.Timestamp;
4
- import java.text.ParseException;
5
- import java.text.SimpleDateFormat;
6
- import java.util.Date;
7
-
8
- import org.junit.Test;
9
- import static org.junit.Assert.assertEquals;
10
-
11
- public class TimestampFormatTest {
12
-
13
- @Test
14
- public void test() throws ParseException
15
- {
16
- Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2015/03/04 17:08:09");
17
- Timestamp t = new Timestamp(date.getTime());
18
-
19
- {
20
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
21
- assertEquals("2015-03-04 17:08:09.000000000", format.format(t));
22
- }
23
- {
24
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 0);
25
- assertEquals("2015-03-04 17:08:09", format.format(t));
26
- }
27
- {
28
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
29
- assertEquals("2015-03-04 17:08:09.0", format.format(t));
30
- }
31
-
32
- t.setNanos(1234567);
33
- {
34
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
35
- assertEquals("2015-03-04 17:08:09.001234567", format.format(t));
36
- }
37
- {
38
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 2);
39
- assertEquals("2015-03-04 17:08:09.00", format.format(t));
40
- }
41
- {
42
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 3);
43
- assertEquals("2015-03-04 17:08:09.001", format.format(t));
44
- }
45
-
46
- t.setNanos(123456789);
47
- {
48
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
49
- assertEquals("2015-03-04 17:08:09.123456789", format.format(t));
50
- }
51
- {
52
- TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
53
- assertEquals("2015-03-04 17:08:09.1", format.format(t));
54
- }
55
- }
56
-
57
- }