embulk-output-oracle 0.7.8 → 0.7.9

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: c509090502c865c3379b81256eafb46d1b646723
4
- data.tar.gz: 9fdd4a4246876a4cc163e6e7cbee46a81b1e46ed
3
+ metadata.gz: ca1526b2ef4b47df791546e857435f62a4cd24c2
4
+ data.tar.gz: dda1b751b35040326ecd19a054ed9ebc8a90d20c
5
5
  SHA512:
6
- metadata.gz: 0d6068d31a3a189ae7b2958e3dd54926e7c5544c4267bbe5b9b5dc7a988729a2e3024f21015a3b1c617320ca760e6764f6d1ca5a1664059f10e0a714ecc6545f
7
- data.tar.gz: fbdb957bf2461d3d31e5b4d712c53f8a06f802eebf122dd7c7b884c50eb515daf7d8c26ab8ff3cec907255fbb867f3c8d4e932e741094738086051a97632a6c3
6
+ metadata.gz: 5f309bc65a52b1848e9684900a82804107387f35b2070cfb54b8a72f3d9db9c8233e8da1e962574ac5f4b8f3042df0e03b7ec28af096607f649c2c6b0be35ed8
7
+ data.tar.gz: b9e324bb613f72f91139beb146f94db2eb8b7699398767fe160b476c38bb6420e2c496abb0cae43f105fbd4507e886c2f73cedab2a0c2f3c3b2d9b6736a403ea
data/README.md CHANGED
@@ -16,6 +16,8 @@ Oracle output plugin for Embulk loads records to Oracle.
16
16
  - **user**: database login user name (string, required)
17
17
  - **password**: database login password (string, default: "")
18
18
  - **database**: destination database name (string, required if url is not set or insert_method is "oci")
19
+ - **schema** destination schema name (string, optional)
20
+ - **temp_schema**: schema name for intermediate tables. by default, intermediate tables will be created in the same schema as destination table. replace mode doesn't support temp_schema. (string, optional)
19
21
  - **url**: URL of the JDBC connection (string, optional)
20
22
  - **table**: destination table name (string, required)
21
23
  - **options**: extra connection properties (hash, default: {})
@@ -42,6 +42,10 @@ public class OracleOutputPlugin
42
42
  @ConfigDefault("null")
43
43
  public Optional<String> getSchema();
44
44
 
45
+ @Config("temp_schema")
46
+ @ConfigDefault("null")
47
+ public Optional<String> getTempSchema();
48
+
45
49
  @Config("url")
46
50
  @ConfigDefault("null")
47
51
  public Optional<String> getUrl();
@@ -122,6 +126,16 @@ public class OracleOutputPlugin
122
126
  return new OracleOutputConnector(url, props, oracleTask.getSchema().orNull(), oracleTask.getInsertMethod() == InsertMethod.direct);
123
127
  }
124
128
 
129
+ @Override
130
+ protected TableIdentifier buildIntermediateTableId(JdbcOutputConnection con, PluginTask task, String tableName) {
131
+ OraclePluginTask oracleTask = (OraclePluginTask) task;
132
+ // replace mode doesn't support temp_schema because ALTER TABLE doesn't support schema.
133
+ if (oracleTask.getTempSchema().isPresent() && oracleTask.getMode() != Mode.REPLACE) {
134
+ return new TableIdentifier(null, oracleTask.getTempSchema().get(), tableName);
135
+ }
136
+ return super.buildIntermediateTableId(con, task, tableName);
137
+ }
138
+
125
139
  @Override
126
140
  protected BatchInsert newBatchInsert(PluginTask task, Optional<MergeConfig> mergeConfig) throws IOException, SQLException
127
141
  {
@@ -144,7 +158,6 @@ public class OracleOutputPlugin
144
158
  String.format("%s:%d/%s", oracleTask.getHost().get(), oracleTask.getPort(), oracleTask.getDatabase().get()),
145
159
  oracleTask.getUser(),
146
160
  oracleTask.getPassword(),
147
- oracleTask.getSchema().orNull(),
148
161
  charset,
149
162
  nationalCharset,
150
163
  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.TableIdentifier;
17
18
  import org.embulk.output.jdbc.TimestampFormat;
18
19
  import org.embulk.output.oracle.oci.ColumnDefinition;
19
20
  import org.embulk.output.oracle.oci.OCI;
@@ -31,7 +32,6 @@ public class DirectBatchInsert implements BatchInsert
31
32
  private final String database;
32
33
  private final String user;
33
34
  private final String password;
34
- private final String schema;
35
35
  private final OracleCharset charset;
36
36
  private final OracleCharset nationalCharset;
37
37
  private final int batchSize;
@@ -41,20 +41,19 @@ public class DirectBatchInsert implements BatchInsert
41
41
  private DateFormat[] formats;
42
42
 
43
43
 
44
- public DirectBatchInsert(String database, String user, String password, String schema,
44
+ public DirectBatchInsert(String database, String user, String password,
45
45
  OracleCharset charset, OracleCharset nationalCharset, int batchSize)
46
46
  {
47
47
  this.database = database;
48
48
  this.user = user;
49
49
  this.password = password;
50
- this.schema = schema;
51
50
  this.charset = charset;
52
51
  this.nationalCharset = nationalCharset;
53
52
  this.batchSize = batchSize;
54
53
  }
55
54
 
56
55
  @Override
57
- public void prepare(String loadTable, JdbcSchema insertSchema) throws SQLException
56
+ public void prepare(TableIdentifier loadTable, JdbcSchema insertSchema) throws SQLException
58
57
  {
59
58
 
60
59
  /*
@@ -141,8 +140,8 @@ public class DirectBatchInsert implements BatchInsert
141
140
 
142
141
  }
143
142
 
144
- TableDefinition tableDefinition = new TableDefinition(schema, loadTable, columns);
145
- ociKey = Arrays.asList(database, user, loadTable);
143
+ TableDefinition tableDefinition = new TableDefinition(loadTable.getSchemaName(), loadTable.getTableName(), columns);
144
+ ociKey = Arrays.asList(database, user, loadTable.getTableName());
146
145
  OCIWrapper oci = ociManager.open(ociKey, database, user, password, tableDefinition, batchSize);
147
146
 
148
147
  buffer = new RowBuffer(oci, tableDefinition);
@@ -11,10 +11,11 @@ import java.util.HashMap;
11
11
  import java.util.List;
12
12
  import java.util.Map;
13
13
 
14
- import org.embulk.output.jdbc.JdbcOutputConnection;
15
14
  import org.embulk.output.jdbc.JdbcColumn;
15
+ import org.embulk.output.jdbc.JdbcOutputConnection;
16
16
  import org.embulk.output.jdbc.JdbcSchema;
17
17
  import org.embulk.output.jdbc.MergeConfig;
18
+ import org.embulk.output.jdbc.TableIdentifier;
18
19
 
19
20
  public class OracleOutputConnection
20
21
  extends JdbcOutputConnection
@@ -63,52 +64,28 @@ public class OracleOutputConnection
63
64
  }
64
65
 
65
66
  @Override
66
- public void dropTableIfExists(String tableName) throws SQLException
67
+ public void dropTableIfExists(TableIdentifier table) throws SQLException
67
68
  {
68
- if (tableExists(tableName)) {
69
- dropTable(tableName);
69
+ if (tableExists(table)) {
70
+ dropTable(table);
70
71
  }
71
72
  }
72
73
 
73
74
  @Override
74
- protected void dropTableIfExists(Statement stmt, String tableName) throws SQLException {
75
- if (tableExists(tableName)) {
76
- dropTable(stmt, tableName);
75
+ protected void dropTableIfExists(Statement stmt, TableIdentifier table) throws SQLException {
76
+ if (tableExists(table)) {
77
+ dropTable(stmt, table);
77
78
  }
78
79
  }
79
80
 
80
81
  @Override
81
- public void createTableIfNotExists(String tableName, JdbcSchema schema) throws SQLException
82
+ public void createTableIfNotExists(TableIdentifier table, JdbcSchema schema) throws SQLException
82
83
  {
83
- if (!tableExists(tableName)) {
84
- createTable(tableName, schema);
84
+ if (!tableExists(table)) {
85
+ createTable(table, schema);
85
86
  }
86
87
  }
87
88
 
88
- public void createTable(String tableName, JdbcSchema schema) throws SQLException
89
- {
90
- Statement stmt = connection.createStatement();
91
- try {
92
- String sql = buildCreateTableSql(tableName, schema);
93
- executeUpdate(stmt, sql);
94
- commitIfNecessary(connection);
95
- } catch (SQLException ex) {
96
- throw safeRollback(connection, ex);
97
- } finally {
98
- stmt.close();
99
- }
100
- }
101
-
102
- protected String buildCreateTableSql(String name, JdbcSchema schema)
103
- {
104
- StringBuilder sb = new StringBuilder();
105
-
106
- sb.append("CREATE TABLE ");
107
- quoteIdentifierString(sb, name);
108
- sb.append(buildCreateTableSchemaSql(schema));
109
- return sb.toString();
110
- }
111
-
112
89
  private static String getSchema(Connection connection) throws SQLException
113
90
  {
114
91
  // Because old Oracle JDBC drivers don't support Connection#getSchema method.
@@ -124,7 +101,19 @@ public class OracleOutputConnection
124
101
  }
125
102
 
126
103
  @Override
127
- protected String buildPreparedInsertSql(String toTable, JdbcSchema toTableSchema) throws SQLException
104
+ protected String buildRenameTableSql(TableIdentifier fromTable, TableIdentifier toTable)
105
+ {
106
+ // ALTER TABLE doesn't support schema
107
+ StringBuilder sb = new StringBuilder();
108
+ sb.append("ALTER TABLE ");
109
+ quoteIdentifierString(sb, fromTable.getTableName());
110
+ sb.append(" RENAME TO ");
111
+ quoteIdentifierString(sb, toTable.getTableName());
112
+ return sb.toString();
113
+ }
114
+
115
+ @Override
116
+ protected String buildPreparedInsertSql(TableIdentifier toTable, JdbcSchema toTableSchema) throws SQLException
128
117
  {
129
118
  String sql = super.buildPreparedInsertSql(toTable, toTableSchema);
130
119
  if (direct) {
@@ -199,12 +188,12 @@ public class OracleOutputConnection
199
188
  }
200
189
 
201
190
  @Override
202
- protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, MergeConfig mergeConfig) throws SQLException
191
+ protected String buildCollectMergeSql(List<TableIdentifier> fromTables, JdbcSchema schema, TableIdentifier toTable, MergeConfig mergeConfig) throws SQLException
203
192
  {
204
193
  StringBuilder sb = new StringBuilder();
205
194
 
206
195
  sb.append("MERGE INTO ");
207
- sb.append(quoteIdentifierString(toTable));
196
+ sb.append(quoteTableIdentifier(toTable));
208
197
  sb.append(" T");
209
198
  sb.append(" USING (");
210
199
  for (int i = 0; i < fromTables.size(); i++) {
@@ -212,7 +201,7 @@ public class OracleOutputConnection
212
201
  sb.append(" SELECT ");
213
202
  sb.append(buildColumns(schema, ""));
214
203
  sb.append(" FROM ");
215
- sb.append(quoteIdentifierString(fromTables.get(i)));
204
+ sb.append(quoteTableIdentifier(fromTables.get(i)));
216
205
  }
217
206
  sb.append(") S");
218
207
  sb.append(" ON (");
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.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-06-23 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.7.8.jar
23
- - classpath/embulk-output-oracle-0.7.8.jar
22
+ - classpath/embulk-output-jdbc-0.7.9.jar
23
+ - classpath/embulk-output-oracle-0.7.9.jar
24
24
  - lib/embulk/native/x86_64-linux/libembulk-output-oracle-oci.so
25
25
  - lib/embulk/native/x86_64-windows/embulk-output-oracle-oci.dll
26
26
  - lib/embulk/output/oracle.rb
Binary file