embulk-output-cdata 0.4.1 → 0.4.3

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: 2a79b482391f04bdffabfda7cadb2bf8fffdcaea
4
- data.tar.gz: 805ef6119099703dfa3591cfb1038f3bd6718657
3
+ metadata.gz: 18fddfcaf92673f9aa5400e736121e9a5b747520
4
+ data.tar.gz: 13789af293c9cbaee3e907a66bdf418154eb56be
5
5
  SHA512:
6
- metadata.gz: fa5485cffa86d2b25359d227a86dd7119ac06ecb1a4783acc21ee9db26c27411e279630f13fc67111c994945112956f8d85b0b83f6e62cdb3c63f994f79247e5
7
- data.tar.gz: 06104206fdc4d697960b937dc92d0e26e8e23d520b9639ae5ad75358f2470626be8bc2f6237a8f98bf2098bd48f66747ebbaab2d2174daac6b9e4c130672114c
6
+ metadata.gz: e97610f95f4bfbf1dd94327dd8b9b10d10c92cba86d41407ce6763e840cfdedc0c436a181695304d7aa0e24d4b0745b6e12738e0e9ea5ac715098e3d8a1e81ae
7
+ data.tar.gz: f4b579d9eb223224e6e96d4b698ac1326255388baa0c1d2d6fb09ddfda9c9aacec9fe453ed277a2acb772ba1387c8d01738ab37cd9f453054702463645a05c90
data/README.md CHANGED
@@ -12,7 +12,7 @@ Support to CData JDBC Driver bulk upsert or update statements.
12
12
  ## Configuration
13
13
 
14
14
  - **driver_path**: description (string, required)
15
- - **class_name**: description (string, required)
15
+ - **driver_class**: description (string, required)
16
16
  - **url**: description (string, `"jdbc:..."`)
17
17
  - **mode**: description (string, `"upsert" | "update"`)
18
18
  - **table**: description (string, required)
data/build.gradle CHANGED
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.4.1"
16
+ version = "0.4.3"
17
17
 
18
18
  sourceCompatibility = 1.8
19
19
  targetCompatibility = 1.8
@@ -25,7 +25,7 @@ public class CDataOutputPlugin
25
25
  @Config("driver_path")
26
26
  String getDriverPath();
27
27
 
28
- @Config("class_name")
28
+ @Config("driver_class")
29
29
  String getDriverName();
30
30
 
31
31
  @Config("url")
@@ -29,9 +29,10 @@ public class CDataPageOutputForManualUpsert extends CDataPageOutputForUpsertBase
29
29
  .map(it -> "?").collect(Collectors.toCollection(ArrayList::new));
30
30
  }
31
31
 
32
- protected void executeInsert(List<String> columnNames, List<String> preparedValues) {
32
+ protected ExecutedInsertResult executeInsert(List<String> columnNames, List<String> preparedValues) {
33
33
  String externalIdColumn = getTask().getExternalIdColumn();
34
34
  String primaryKeyColumn = getTask().getDefaultPrimaryKey();
35
+ ExecutedInsertResult result = new ExecutedInsertResult();
35
36
 
36
37
  try {
37
38
  // split insert to InsertTemp#TEMP and UpdateTemp#TEMP
@@ -55,6 +56,7 @@ public class CDataPageOutputForManualUpsert extends CDataPageOutputForUpsertBase
55
56
 
56
57
  String externalIdValue = getPageReader().getString(externalIdColumnIndex);
57
58
  if (externalIdValueAndPrimaryKeyValueMap.containsKey(externalIdValue)) {
59
+ result.selectUpdateRecordCount++;
58
60
  String PrimaryKeyColumnValue = externalIdValueAndPrimaryKeyValueMap.get(externalIdValue);
59
61
 
60
62
  List<String> updateColumnNames = new ArrayList<>(columnNames);
@@ -77,6 +79,7 @@ public class CDataPageOutputForManualUpsert extends CDataPageOutputForUpsertBase
77
79
  logger.info("inserted to " + UPDATE_TEMP_TABLE);
78
80
 
79
81
  } else {
82
+ result.selectInsertRecordCount++;
80
83
  // new record, insert to InsertTemp#TEMP
81
84
  String insertStatement = createInsertQuery(INSERT_TEMP_TABLE, columnNames, preparedValues);
82
85
  try (PreparedStatement insertPreparedStatement = getConnection().prepareStatement(insertStatement, Statement.RETURN_GENERATED_KEYS)) {
@@ -92,6 +95,7 @@ public class CDataPageOutputForManualUpsert extends CDataPageOutputForUpsertBase
92
95
  } catch (SQLException e) {
93
96
  throw new RuntimeException(e);
94
97
  }
98
+ return result;
95
99
  }
96
100
 
97
101
  protected String createInsertIntoSelectQuery(String tableName, List<String> columnNames) {
@@ -110,14 +114,21 @@ public class CDataPageOutputForManualUpsert extends CDataPageOutputForUpsertBase
110
114
  " FROM " + UPDATE_TEMP_TABLE;
111
115
  }
112
116
 
113
- protected String executeUpsert(String tableName, List<String> columnNames) throws SQLException {
117
+ protected String executeUpsert(String tableName, List<String> columnNames, ExecutedInsertResult result) throws SQLException {
114
118
 
115
119
  String insertIntoSelectQuery = createInsertIntoSelectQuery(tableName, columnNames);
120
+
121
+ boolean mustBeAddPrimaryKey = !Objects.equals(getTask().getDefaultPrimaryKey(), getTask().getExternalIdColumn());
122
+ if (mustBeAddPrimaryKey) {
123
+ columnNames.add(getTask().getDefaultPrimaryKey());
124
+ }
116
125
  String updateIntoSelectQuery = createUpdateIntoSelectQuery(tableName, columnNames);
117
126
 
118
- getConnection()
119
- .createStatement()
120
- .executeUpdate(insertIntoSelectQuery, Statement.RETURN_GENERATED_KEYS);
127
+ if (result.selectInsertRecordCount > 0) {
128
+ getConnection()
129
+ .createStatement()
130
+ .executeUpdate(insertIntoSelectQuery, Statement.RETURN_GENERATED_KEYS);
131
+ }
121
132
 
122
133
  getConnection()
123
134
  .createStatement()
@@ -41,7 +41,7 @@ public class CDataPageOutputForUpsert extends CDataPageOutputForUpsertBase {
41
41
  " FROM Temp#TEMP";
42
42
  }
43
43
 
44
- protected void executeInsert(List<String> columnNames, List<String> preparedValues) throws SQLException {
44
+ protected ExecutedInsertResult executeInsert(List<String> columnNames, List<String> preparedValues) throws SQLException {
45
45
  String insertStatement = createInsertQuery("Temp#TEMP", columnNames, preparedValues);
46
46
  logger.info(insertStatement);
47
47
 
@@ -49,8 +49,11 @@ public class CDataPageOutputForUpsert extends CDataPageOutputForUpsertBase {
49
49
  Connection conn = getConnection();
50
50
  CDataOutputPlugin.PluginTask task = getTask();
51
51
 
52
+ ExecutedInsertResult result = new ExecutedInsertResult();
53
+
52
54
  while (pageReader.nextRecord()) {
53
55
  try {
56
+ result.selectUpsertRecordCount++;
54
57
  PreparedStatement preparedStatement = conn.prepareStatement(insertStatement, Statement.RETURN_GENERATED_KEYS);
55
58
 
56
59
  pageReader.getSchema().visitColumns(createColumnVisitor(preparedStatement));
@@ -62,9 +65,10 @@ public class CDataPageOutputForUpsert extends CDataPageOutputForUpsertBase {
62
65
  throw new RuntimeException(e);
63
66
  }
64
67
  }
68
+ return result;
65
69
  }
66
70
 
67
- protected String executeUpsert(String tableName, List<String> columnNames) throws SQLException {
71
+ protected String executeUpsert(String tableName, List<String> columnNames, ExecutedInsertResult result) throws SQLException {
68
72
  String upsertStatement = createUpsertQuery(tableName, columnNames);
69
73
  getConnection().createStatement().executeUpdate(upsertStatement, Statement.RETURN_GENERATED_KEYS);
70
74
  return upsertStatement;
@@ -27,15 +27,16 @@ public class CDataPageOutputForUpsertBase implements TransactionalPageOutput {
27
27
  pageReader.setPage(page);
28
28
  List<String> columnNames = createColumns();
29
29
  List<String> preparedValues = createPlaceHolders(); // for ExternalIdColumn
30
+ ExecutedInsertResult result;
30
31
 
31
32
  try {
32
- executeInsert(columnNames, preparedValues);
33
+ result = executeInsert(columnNames, preparedValues);
33
34
  } catch (SQLException e) {
34
35
  throw new RuntimeException(e);
35
36
  }
36
37
 
37
38
  try {
38
- String upsertStatement = executeUpsert(task.getTable(), columnNames);
39
+ String upsertStatement = executeUpsert(task.getTable(), columnNames, result);
39
40
  logger.info(upsertStatement);
40
41
  } catch (SQLException e) {
41
42
  throw new RuntimeException(e);
@@ -112,9 +113,10 @@ public class CDataPageOutputForUpsertBase implements TransactionalPageOutput {
112
113
  * insert into Temp table
113
114
  * @param columnNames
114
115
  * @param preparedValues
116
+ * @return ExecutedInsertResult
115
117
  * @throws SQLException
116
118
  */
117
- protected void executeInsert(List<String> columnNames, List<String> preparedValues) throws SQLException {
119
+ protected ExecutedInsertResult executeInsert(List<String> columnNames, List<String> preparedValues) throws SQLException {
118
120
  throw new UnsupportedOperationException("executeInsert is not implemented");
119
121
  }
120
122
 
@@ -123,10 +125,11 @@ public class CDataPageOutputForUpsertBase implements TransactionalPageOutput {
123
125
  * when not upsert query un suppoerted, must be use "INSERT INTO SELECT" and "UPDATE SELECT" in this method
124
126
  * @param tableName
125
127
  * @param columnNames
128
+ * @param result
126
129
  * @return query string, use for logging
127
130
  * @throws SQLException
128
131
  */
129
- protected String executeUpsert(String tableName, List<String> columnNames) throws SQLException {
132
+ protected String executeUpsert(String tableName, List<String> columnNames, ExecutedInsertResult result) throws SQLException {
130
133
  throw new RuntimeException("Not implemented");
131
134
  }
132
135
 
@@ -193,4 +196,10 @@ public class CDataPageOutputForUpsertBase implements TransactionalPageOutput {
193
196
  }
194
197
  };
195
198
  }
199
+
200
+ protected class ExecutedInsertResult {
201
+ int selectInsertRecordCount = 0;
202
+ int selectUpdateRecordCount = 0;
203
+ int selectUpsertRecordCount = 0;
204
+ }
196
205
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-cdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sampo02
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-25 00:00:00.000000000 Z
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ files:
49
49
  - LICENSE.txt
50
50
  - README.md
51
51
  - build.gradle
52
- - classpath/embulk-output-cdata-0.4.1.jar
52
+ - classpath/embulk-output-cdata-0.4.3.jar
53
53
  - config/checkstyle/checkstyle.xml
54
54
  - config/checkstyle/default.xml
55
55
  - gradle/wrapper/gradle-wrapper.jar