embulk-input-jdbc 0.9.3 → 0.10.0

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
- SHA1:
3
- metadata.gz: 89f25bb2c92757d6e3f6aad8cdd9721d58eb216c
4
- data.tar.gz: f1195041a5488157685ba4f435b5e0e67276f107
2
+ SHA256:
3
+ metadata.gz: 2b562467675dad44be8b2a8520d59f757c4324605c7fc6a49fe5a88f7ce3015e
4
+ data.tar.gz: 6bd9630ac812f6c4dbd839878458dec1084b29a48c573f3c8c728c673ff6ce05
5
5
  SHA512:
6
- metadata.gz: 66aded100ed9af8b837e9b9d12cf0d43cda252a5f909b6d0d0bbea97143fd3165d02882c5e54aaa3c1f49ab2e4fd804fa7f4bb33c54a915aca282a0be63588ef
7
- data.tar.gz: 95bb8bea452106e630740f6ea239a2556c8bee1c36be9fef6318f2be97efc53eefc8844b342b7aba7ea5e659941b63527528ee6392dba9becbab67c1497eafdb
6
+ metadata.gz: 3c117eb02df61b64e09380a9b6ebe2837a0f3cab5185ccd4453fa90485870d4a114f9918c69c00595802c052daac158d856641e237057f2ebfe2ffc0275740f8
7
+ data.tar.gz: 91d7b9dae3f561314af06cd45ec59248fe6b34c904aed5dc0901cbdd5fcbe9ece54265a036e691bc11a2679bae359512d2b25c7f9db2ca0b865df07018934975
data/README.md CHANGED
@@ -29,8 +29,8 @@ Generic JDBC input plugin for Embulk loads records from a database using a JDBC
29
29
  - **where**: WHERE condition to filter the rows (string, default: no-condition)
30
30
  - **order_by**: expression of ORDER BY to sort rows (e.g. `created_at DESC, id ASC`) (string, default: not sorted)
31
31
  - **default_timezone**: If the sql type of a column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted int this default_timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
32
- - **default_column_options**: column_options for each JDBC type as default. Key is a JDBC type (e.g. 'DATE', 'BIGINT'). Value is same as column_options's value.
33
- - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
32
+ - **default_column_options**: advanced: column_options for each JDBC type as default. key-value pairs where key is a JDBC type (e.g. 'DATE', 'BIGINT') and value is same as column_options's value.
33
+ - **column_options**: advanced: key-value pairs where key is a column name and value is options for the column.
34
34
  - **value_type**: embulk get values from database as this value_type. Typically, the value_type determines `getXXX` method of `java.sql.PreparedStatement`. `value_type: json` is an exception which uses `getString` and parses the result as a JSON string.
35
35
  (string, default: depends on the sql type of the column. Available values options are: `long`, `double`, `float`, `decimal`, `boolean`, `string`, `json`, `date`, `time`, `timestamp`)
36
36
  - **type**: Column values are converted to this embulk type.
@@ -39,6 +39,8 @@ Generic JDBC input plugin for Embulk loads records from a database using a JDBC
39
39
  - **timestamp_format**: If the sql type of the column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted by this timestamp_format. And if the embulk type is `timestamp`, this timestamp_format may be used in the output plugin. For example, stdout plugin use the timestamp_format, but *csv formatter plugin doesn't use*. (string, default : `%Y-%m-%d` for `date`, `%H:%M:%S` for `time`, `%Y-%m-%d %H:%M:%S` for `timestamp`)
40
40
  - **timezone**: If the sql type of the column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted in this timezone.
41
41
  (string, value of default_timezone option is used by default)
42
+ - **before_setup**: if set, this SQL will be executed before setup. You can prepare table for input by this option.
43
+ - **before_select**: if set, this SQL will be executed before the SELECT query in the same transaction.
42
44
  - **after_select**: if set, this SQL will be executed after the SELECT query in the same transaction.
43
45
 
44
46
 
@@ -77,6 +79,8 @@ CREATE INDEX embulk_incremental_loading_index ON table (updated_at, id);
77
79
 
78
80
  Recommended usage is to leave `incremental_columns` unset and let this plugin automatically finds an auto-increment primary key. Currently, only strings and integers are supported as incremental_columns.
79
81
 
82
+ TIMESTAMP, TIMESTAMPTZ, DATE and DATETIME are also supported depends on each RDBMS
83
+
80
84
  ### Use incremental loading with raw query
81
85
 
82
86
  **IMPORTANT**: This is an advanced feature and assume you have an enough knowledge about incremental loading using Embulk and this plugin
@@ -166,7 +170,7 @@ in:
166
170
  select: "col1, col2, col3"
167
171
  where: "col4 != 'a'"
168
172
  default_column_options:
169
- DATE: { type: string, timestamp_format: "%Y/%m/%d", timezone: "+0900"}
173
+ TIMESTAMP: { type: string, timestamp_format: "%Y/%m/%d %H:%M:%S", timezone: "+0900"}
170
174
  BIGINT: { type: string }
171
175
  column_options:
172
176
  col1: {type: long}
@@ -151,6 +151,14 @@ public abstract class AbstractJdbcInputPlugin
151
151
  @ConfigDefault("{}")
152
152
  public Map<String, JdbcColumnOption> getDefaultColumnOptions();
153
153
 
154
+ @Config("before_setup")
155
+ @ConfigDefault("null")
156
+ public Optional<String> getBeforeSetup();
157
+
158
+ @Config("before_select")
159
+ @ConfigDefault("null")
160
+ public Optional<String> getBeforeSelect();
161
+
154
162
  @Config("after_select")
155
163
  @ConfigDefault("null")
156
164
  public Optional<String> getAfterSelect();
@@ -197,6 +205,11 @@ public abstract class AbstractJdbcInputPlugin
197
205
  try (JdbcInputConnection con = newConnection(task)) {
198
206
  con.showDriverVersion();
199
207
 
208
+ if (task.getBeforeSetup().isPresent()) {
209
+ con.executeUpdate(task.getBeforeSetup().get());
210
+ con.commit();
211
+ }
212
+
200
213
  // TODO incremental_columns is not set => get primary key
201
214
  schema = setupTask(con, task);
202
215
  } catch (SQLException ex) {
@@ -474,6 +487,10 @@ public abstract class AbstractJdbcInputPlugin
474
487
  LastRecordStore lastRecordStore = null;
475
488
 
476
489
  try (JdbcInputConnection con = newConnection(task)) {
490
+ if (task.getBeforeSelect().isPresent()) {
491
+ con.executeUpdate(task.getBeforeSelect().get());
492
+ }
493
+
477
494
  List<ColumnGetter> getters = newColumnGetters(con, task, querySchema, pageBuilder);
478
495
  try (BatchSelect cursor = con.newSelectCursor(builtQuery, getters, task.getFetchRows(), task.getSocketTimeout())) {
479
496
  while (true) {
@@ -503,8 +520,9 @@ public abstract class AbstractJdbcInputPlugin
503
520
  // after_commit moves those values to the actual table.
504
521
  if (task.getAfterSelect().isPresent()) {
505
522
  con.executeUpdate(task.getAfterSelect().get());
506
- con.connection.commit();
507
523
  }
524
+ con.commit();
525
+
508
526
  } catch (SQLException ex) {
509
527
  throw Throwables.propagate(ex);
510
528
  }
@@ -480,8 +480,14 @@ public class JdbcInputConnection
480
480
  }
481
481
  }
482
482
 
483
- public void showDriverVersion() throws SQLException {
483
+ public void showDriverVersion() throws SQLException
484
+ {
484
485
  DatabaseMetaData meta = connection.getMetaData();
485
486
  logger.info(String.format(Locale.ENGLISH,"Using JDBC Driver %s",meta.getDriverVersion()));
486
487
  }
488
+
489
+ public void commit() throws SQLException
490
+ {
491
+ connection.commit();
492
+ }
487
493
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from 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-input-jdbc-0.9.3.jar
22
+ - classpath/embulk-input-jdbc-0.10.0.jar
23
23
  - lib/embulk/input/jdbc.rb
24
24
  - src/main/java/org/embulk/input/JdbcInputPlugin.java
25
25
  - src/main/java/org/embulk/input/jdbc/AbstractJdbcInputPlugin.java
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.4.8
71
+ rubygems_version: 2.6.13
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: JDBC input plugin for Embulk