embulk-output-jdbc 0.7.6 → 0.7.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d34620b8b097cd388a2c29b0f2d7e395ea9aa858
|
4
|
+
data.tar.gz: fc7b31df19c617e9a9e930417c372d3d9f0be981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aba1b8193aaf2d5e3bc02a5148442c7b74ddd579eaf8c1ea701d30447a7105b45df5f26251de6607e7a27bc394f77f200e3df4d5ca16e53adc4af81c836bc8b8
|
7
|
+
data.tar.gz: 6ddf11bed1077c07a5e5f2610b509881cdea9f1bc1276d9a8923cecc7cad9317365259483c5be7d249961c73c6d3ba665258a052e57f2aa4251018214692abe5
|
data/README.md
CHANGED
@@ -30,6 +30,7 @@ Generic JDBC output plugin for Embulk loads records to a database using a JDBC d
|
|
30
30
|
- **value_type**: This plugin converts input column type (embulk type) into a database type to build a INSERT statement. This value_type option controls the type of the value in a INSERT statement. (string, default: depends on the sql type of the column. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `json`, `null`, `pass`)
|
31
31
|
- **timestamp_format**: If input column type (embulk type) is timestamp and value_type is `string` or `nstring`, this plugin needs to format the timestamp value into a string. This timestamp_format option is used to control the format of the timestamp. (string, default: `%Y-%m-%d %H:%M:%S.%6N`)
|
32
32
|
- **timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp value into a SQL string. In this cases, this timezone option is used to control the timezone. (string, value of default_timezone option is used by default)
|
33
|
+
- **before_load**: if set, this SQL will be executed before loading all records. In truncate_insert mode, the SQL will be executed after truncating. replace mode doesn't support this option.
|
33
34
|
- **after_load**: if set, this SQL will be executed after loading all records.
|
34
35
|
|
35
36
|
## Modes
|
Binary file
|
@@ -108,6 +108,10 @@ public abstract class AbstractJdbcOutputPlugin
|
|
108
108
|
@ConfigDefault("null")
|
109
109
|
public Optional<List<String>> getMergeRule();
|
110
110
|
|
111
|
+
@Config("before_load")
|
112
|
+
@ConfigDefault("null")
|
113
|
+
public Optional<String> getBeforeLoad();
|
114
|
+
|
111
115
|
@Config("after_load")
|
112
116
|
@ConfigDefault("null")
|
113
117
|
public Optional<String> getAfterLoad();
|
@@ -453,6 +457,10 @@ public abstract class AbstractJdbcOutputPlugin
|
|
453
457
|
Mode mode = task.getMode();
|
454
458
|
logger.info("Using {} mode", mode);
|
455
459
|
|
460
|
+
if (mode.commitBySwapTable() && task.getBeforeLoad().isPresent()) {
|
461
|
+
throw new ConfigException(String.format("%s mode does not support 'before_load' option.", mode));
|
462
|
+
}
|
463
|
+
|
456
464
|
if (con.tableExists(task.getTable())) {
|
457
465
|
task.setActualTable(task.getTable());
|
458
466
|
} else {
|
@@ -514,6 +522,9 @@ public abstract class AbstractJdbcOutputPlugin
|
|
514
522
|
}
|
515
523
|
} else {
|
516
524
|
task.setIntermediateTables(Optional.<List<String>>absent());
|
525
|
+
if (task.getBeforeLoad().isPresent()) {
|
526
|
+
con.executeSql(task.getBeforeLoad().get());
|
527
|
+
}
|
517
528
|
}
|
518
529
|
|
519
530
|
// build JdbcSchema from a table
|
@@ -675,7 +686,7 @@ public abstract class AbstractJdbcOutputPlugin
|
|
675
686
|
switch (task.getMode()) {
|
676
687
|
case INSERT_DIRECT:
|
677
688
|
case MERGE_DIRECT:
|
678
|
-
// already
|
689
|
+
// already loaded
|
679
690
|
if (task.getAfterLoad().isPresent()) {
|
680
691
|
con.executeSql(task.getAfterLoad().get());
|
681
692
|
}
|
@@ -686,7 +697,7 @@ public abstract class AbstractJdbcOutputPlugin
|
|
686
697
|
if (task.getNewTableSchema().isPresent()) {
|
687
698
|
con.createTableIfNotExists(task.getActualTable(), task.getNewTableSchema().get());
|
688
699
|
}
|
689
|
-
con.collectInsert(task.getIntermediateTables().get(), schema, task.getActualTable(), false, task.getAfterLoad());
|
700
|
+
con.collectInsert(task.getIntermediateTables().get(), schema, task.getActualTable(), false, task.getBeforeLoad(), task.getAfterLoad());
|
690
701
|
break;
|
691
702
|
|
692
703
|
case TRUNCATE_INSERT:
|
@@ -694,7 +705,7 @@ public abstract class AbstractJdbcOutputPlugin
|
|
694
705
|
if (task.getNewTableSchema().isPresent()) {
|
695
706
|
con.createTableIfNotExists(task.getActualTable(), task.getNewTableSchema().get());
|
696
707
|
}
|
697
|
-
con.collectInsert(task.getIntermediateTables().get(), schema, task.getActualTable(), true, task.getAfterLoad());
|
708
|
+
con.collectInsert(task.getIntermediateTables().get(), schema, task.getActualTable(), true, task.getBeforeLoad(), task.getAfterLoad());
|
698
709
|
break;
|
699
710
|
|
700
711
|
case MERGE:
|
@@ -703,7 +714,7 @@ public abstract class AbstractJdbcOutputPlugin
|
|
703
714
|
con.createTableIfNotExists(task.getActualTable(), task.getNewTableSchema().get());
|
704
715
|
}
|
705
716
|
con.collectMerge(task.getIntermediateTables().get(), schema, task.getActualTable(),
|
706
|
-
new MergeConfig(task.getMergeKeys().get(), task.getMergeRule()), task.getAfterLoad());
|
717
|
+
new MergeConfig(task.getMergeKeys().get(), task.getMergeRule()), task.getBeforeLoad(), task.getAfterLoad());
|
707
718
|
break;
|
708
719
|
|
709
720
|
case REPLACE:
|
@@ -294,7 +294,7 @@ public class JdbcOutputConnection
|
|
294
294
|
}
|
295
295
|
|
296
296
|
protected void collectInsert(List<String> fromTables, JdbcSchema schema, String toTable,
|
297
|
-
boolean truncateDestinationFirst, Optional<String>
|
297
|
+
boolean truncateDestinationFirst, Optional<String> preSql, Optional<String> postSql) throws SQLException
|
298
298
|
{
|
299
299
|
if (fromTables.isEmpty()) {
|
300
300
|
return;
|
@@ -306,11 +306,18 @@ public class JdbcOutputConnection
|
|
306
306
|
String sql = buildTruncateSql(toTable);
|
307
307
|
executeUpdate(stmt, sql);
|
308
308
|
}
|
309
|
+
|
310
|
+
if (preSql.isPresent()) {
|
311
|
+
executeUpdate(stmt, preSql.get());
|
312
|
+
}
|
313
|
+
|
309
314
|
String sql = buildCollectInsertSql(fromTables, schema, toTable);
|
310
315
|
executeUpdate(stmt, sql);
|
311
|
-
|
312
|
-
|
316
|
+
|
317
|
+
if (postSql.isPresent()) {
|
318
|
+
executeUpdate(stmt, postSql.get());
|
313
319
|
}
|
320
|
+
|
314
321
|
commitIfNecessary(connection);
|
315
322
|
} catch (SQLException ex) {
|
316
323
|
throw safeRollback(connection, ex);
|
@@ -356,7 +363,7 @@ public class JdbcOutputConnection
|
|
356
363
|
}
|
357
364
|
|
358
365
|
protected void collectMerge(List<String> fromTables, JdbcSchema schema, String toTable, MergeConfig mergeConfig,
|
359
|
-
Optional<String>
|
366
|
+
Optional<String> preSql, Optional<String> postSql) throws SQLException
|
360
367
|
{
|
361
368
|
if (fromTables.isEmpty()) {
|
362
369
|
return;
|
@@ -364,11 +371,17 @@ public class JdbcOutputConnection
|
|
364
371
|
|
365
372
|
Statement stmt = connection.createStatement();
|
366
373
|
try {
|
374
|
+
if (preSql.isPresent()) {
|
375
|
+
executeUpdate(stmt, preSql.get());
|
376
|
+
}
|
377
|
+
|
367
378
|
String sql = buildCollectMergeSql(fromTables, schema, toTable, mergeConfig);
|
368
379
|
executeUpdate(stmt, sql);
|
369
|
-
|
370
|
-
|
380
|
+
|
381
|
+
if (postSql.isPresent()) {
|
382
|
+
executeUpdate(stmt, postSql.get());
|
371
383
|
}
|
384
|
+
|
372
385
|
commitIfNecessary(connection);
|
373
386
|
} catch (SQLException ex) {
|
374
387
|
throw safeRollback(connection, ex);
|
@@ -382,15 +395,18 @@ public class JdbcOutputConnection
|
|
382
395
|
throw new UnsupportedOperationException("not implemented");
|
383
396
|
}
|
384
397
|
|
385
|
-
public void replaceTable(String fromTable, JdbcSchema schema, String toTable, Optional<String>
|
398
|
+
public void replaceTable(String fromTable, JdbcSchema schema, String toTable, Optional<String> postSql) throws SQLException
|
386
399
|
{
|
387
400
|
Statement stmt = connection.createStatement();
|
388
401
|
try {
|
389
402
|
dropTableIfExists(stmt, toTable);
|
403
|
+
|
390
404
|
executeUpdate(stmt, buildRenameTableSql(fromTable, toTable));
|
391
|
-
|
392
|
-
|
405
|
+
|
406
|
+
if (postSql.isPresent()) {
|
407
|
+
executeUpdate(stmt, postSql.get());
|
393
408
|
}
|
409
|
+
|
394
410
|
commitIfNecessary(connection);
|
395
411
|
} catch (SQLException ex) {
|
396
412
|
throw safeRollback(connection, ex);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
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-
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -19,7 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- build.gradle
|
22
|
-
- classpath/embulk-output-jdbc-0.7.
|
22
|
+
- classpath/embulk-output-jdbc-0.7.7.jar
|
23
23
|
- lib/embulk/output/jdbc.rb
|
24
24
|
- src/main/java/org/embulk/output/JdbcOutputPlugin.java
|
25
25
|
- src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java
|