embulk-filter-mssql_lookup 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,368 +1,368 @@
1
- package org.embulk.filter.mssql_lookup;
2
-
3
- import com.google.common.base.Optional;
4
- import com.google.common.collect.ImmutableList;
5
- import org.embulk.config.*;
6
- import org.embulk.spi.*;
7
- import org.embulk.spi.type.Types;
8
-
9
- import java.sql.Connection;
10
- import java.sql.ResultSet;
11
- import java.sql.SQLException;
12
- import java.sql.Statement;
13
- import java.time.Instant;
14
- import java.util.ArrayList;
15
- import java.util.HashMap;
16
- import java.util.List;
17
- import java.util.Map;
18
-
19
- public class MssqlLookupFilterPlugin
20
- implements FilterPlugin
21
- {
22
- public interface PluginTask
23
- extends Task
24
- {
25
- @Config("host")
26
- public String getHost();
27
-
28
- @Config("database")
29
- public String getDatabase();
30
-
31
- @Config("table_name")
32
- public String getTableName();
33
-
34
- @Config("username")
35
- public String getUserName();
36
-
37
- @Config("password")
38
- public String getPassword();
39
-
40
- @Config("mapping_from")
41
- public List<String> getMappingFrom();
42
-
43
- @Config("mapping_to")
44
- public List<String> getMappingTo();
45
-
46
- @Config("new_columns")
47
- public SchemaConfig getNewColumns();
48
-
49
- @Config("driver_path")
50
- @ConfigDefault("null")
51
- public java.util.Optional<String> getDriverPath();
52
-
53
- @Config("driver_class")
54
- @ConfigDefault("null")
55
- public Optional<String> getDriverClass();
56
-
57
- @Config("schemaName")
58
- @ConfigDefault("null")
59
- public Optional<String> getSchemaName();
60
-
61
- }
62
-
63
- @Override
64
- public void transaction(ConfigSource config, Schema inputSchema,
65
- FilterPlugin.Control control)
66
- {
67
- PluginTask task = config.loadConfig(PluginTask.class);
68
-
69
- List<String> inputColumns = task.getMappingFrom();
70
- List<String> keyColumns = task.getMappingTo();
71
- if(inputColumns.size()!=keyColumns.size()){
72
- throw new RuntimeException("Number of mapping_from columns must be exactly equals to number of mapping_to columns");
73
- }
74
-
75
- Schema outputSchema = inputSchema;
76
-
77
- ImmutableList.Builder<Column> builder = ImmutableList.builder();
78
- int i = 0;
79
- for (Column inputColumn : inputSchema.getColumns()) {
80
- Column outputColumn = new Column(i++, inputColumn.getName(), inputColumn.getType());
81
- builder.add(outputColumn);
82
- }
83
-
84
- for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
85
- builder.add(columnConfig.toColumn(i++));
86
- }
87
- outputSchema = new Schema(builder.build());
88
-
89
- control.run(task.dump(), outputSchema);
90
- }
91
-
92
- @Override
93
- public PageOutput open(TaskSource taskSource, Schema inputSchema,
94
- Schema outputSchema, PageOutput output)
95
- {
96
- PluginTask task = taskSource.loadTask(PluginTask.class);
97
- Map<String, List<String>> map = new HashMap<>();
98
- try {
99
- map = getKeyValueMap(task);
100
- } catch (SQLException e) {
101
- e.printStackTrace();
102
- }
103
- PageReader pageReader = new PageReader(inputSchema);
104
- return new MyOutput(pageReader, inputSchema, outputSchema, output, task, map);
105
- }
106
- private Map<String, List<String>> getKeyValueMap(PluginTask task) throws SQLException {
107
- Map<String, List<String>> map = new HashMap<>();
108
- Connection con = DatabaseConnection.getConnection(task);
109
- try {
110
- List<String> targetColumns = task.getMappingTo();
111
- List<String> newColumns = new ArrayList<>();
112
-
113
- for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
114
- newColumns.add(columnConfig.getName());
115
- }
116
-
117
- String query = "select ";
118
- String columnNeedsToBeFetched = "";
119
- for (int i = 0; i < targetColumns.size(); i++) {
120
- columnNeedsToBeFetched += targetColumns.get(i) + ",";
121
- }
122
- for (int i = 0; i < newColumns.size(); i++) {
123
- if (i != newColumns.size() - 1) {
124
- columnNeedsToBeFetched += newColumns.get(i) + ",";
125
- } else {
126
- columnNeedsToBeFetched += newColumns.get(i);
127
- }
128
- }
129
- if (task.getSchemaName().isPresent()) {
130
- query += columnNeedsToBeFetched + " from " + task.getSchemaName().get() + "." + task.getTableName();
131
- }else {
132
- query += columnNeedsToBeFetched + " from " + task.getTableName();
133
-
134
- }
135
- Statement stmt = con.createStatement();
136
- ResultSet rs = stmt.executeQuery(query);
137
-
138
- while (rs.next()) {
139
-
140
- //for key
141
- String key = "";
142
- String comp = "";
143
- for (int i = 0; i < targetColumns.size(); i++) {
144
- comp = "" + rs.getString(targetColumns.get(i));
145
- if (comp.equalsIgnoreCase("null")) {
146
- key += "";
147
- } else {
148
- key += rs.getString(targetColumns.get(i));
149
- }
150
- if (i != targetColumns.size() - 1) {
151
- key += ",";
152
- }
153
- }
154
-
155
- //for values
156
- List<String> keyArray = new ArrayList<>();
157
- for (int i = 0; i < newColumns.size(); i++) {
158
- comp = "" + rs.getString(newColumns.get(i));
159
- if (comp.equalsIgnoreCase("null")) {
160
- keyArray.add("");
161
- } else {
162
- keyArray.add(rs.getString(newColumns.get(i)));
163
- }
164
- }
165
- map.put(key, keyArray);
166
-
167
- }
168
- } catch (Exception e) {
169
- e.printStackTrace();
170
- } finally {
171
- con.close();
172
- }
173
- return map;
174
- }
175
- public static class MyOutput implements PageOutput {
176
- private PageReader reader;
177
- private PageBuilder builder;
178
- private PluginTask task;
179
- private Schema inputSchema;
180
- private Map<String, List<String>> keyValuePair;
181
-
182
- public MyOutput(PageReader pageReader, Schema inputSchema, Schema outputSchema, PageOutput pageOutput, PluginTask task, Map<String, List<String>> keyValuePair) {
183
- this.reader = pageReader;
184
- this.builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, pageOutput);
185
- this.task = task;
186
- this.inputSchema = inputSchema;
187
- this.keyValuePair = keyValuePair;
188
- }
189
-
190
- @Override
191
- public void add(Page page) {
192
- reader.setPage(page);
193
- List<ColumnConfig> columnConfigList = new ArrayList<>();
194
- for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
195
- columnConfigList.add(columnConfig);
196
- }
197
-
198
- while (reader.nextRecord()) {
199
-
200
- int colNum = 0;
201
- List<String> inputColumns = task.getMappingFrom();
202
- List<String> searchingKeyData = new ArrayList<>();
203
- Map<String, Integer> keyMap = new HashMap<>();
204
- keyMap.put("Key", 0);
205
-
206
- for (Column column : inputSchema.getColumns()) {
207
- if (reader.isNull(column)) {
208
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
209
- searchingKeyData.add("");
210
- int key = keyMap.get("Key");
211
- keyMap.put("Key", ++key);
212
- }
213
- builder.setNull(colNum++);
214
- } else {
215
- add_builder(colNum++, column, searchingKeyData, inputColumns, keyMap);
216
- }
217
- }
218
-
219
- String key = "";
220
- for (int k = 0; k < searchingKeyData.size(); k++) {
221
- key += searchingKeyData.get(k);
222
- if (k != searchingKeyData.size() - 1) {
223
- key += ",";
224
- }
225
- }
226
-
227
- List<String> matchedData = new ArrayList<>();
228
- if (keyValuePair.containsKey(key)) {
229
- matchedData = keyValuePair.get(key);
230
- }
231
-
232
- if (matchedData.size() == 0) {
233
- for (int k = 0; k < columnConfigList.size(); k++) {
234
- add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), "", false);
235
- colNum++;
236
- }
237
- } else {
238
- for (int k = 0; k < columnConfigList.size(); k++) {
239
- add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), matchedData.get(k), true);
240
- colNum++;
241
- }
242
- }
243
- builder.addRecord();
244
- }
245
- }
246
-
247
- @Override
248
- public void finish() {
249
- builder.finish();
250
- }
251
-
252
- @Override
253
- public void close() {
254
- builder.close();
255
- }
256
-
257
- private void add_builder(int colNum, Column column, List<String> searchingKeyData, List<String> inputColumns, Map<String, Integer> keyMap) {
258
- if (Types.STRING.equals(column.getType())) {
259
- if (keyMap.get("Key") < inputColumns.size()) {
260
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
261
- searchingKeyData.add(reader.getString(column));
262
- int key = keyMap.get("Key");
263
- keyMap.put("Key", ++key);
264
- }
265
- }
266
- builder.setString(colNum, reader.getString(column));
267
- } else if (Types.BOOLEAN.equals(column.getType())) {
268
- if (keyMap.get("Key") < inputColumns.size()) {
269
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
270
- searchingKeyData.add(String.valueOf(reader.getBoolean(column)));
271
- int key = keyMap.get("Key");
272
- keyMap.put("Key", ++key);
273
- }
274
- }
275
- builder.setBoolean(colNum, reader.getBoolean(column));
276
- } else if (Types.DOUBLE.equals(column.getType())) {
277
- if (keyMap.get("Key") < inputColumns.size()) {
278
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
279
- searchingKeyData.add(String.valueOf(reader.getDouble(column)));
280
- int key = keyMap.get("Key");
281
- keyMap.put("Key", ++key);
282
- }
283
- }
284
- builder.setDouble(colNum, reader.getDouble(column));
285
- } else if (Types.LONG.equals(column.getType())) {
286
- if (keyMap.get("Key") < inputColumns.size()) {
287
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
288
- searchingKeyData.add(String.valueOf(reader.getLong(column)));
289
- int key = keyMap.get("Key");
290
- keyMap.put("Key", ++key);
291
- }
292
- }
293
-
294
- builder.setLong(colNum, reader.getLong(column));
295
- } else if (Types.TIMESTAMP.equals(column.getType())) {
296
- if (keyMap.get("Key") < inputColumns.size()) {
297
- if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
298
- searchingKeyData.add(String.valueOf(reader.getTimestamp(column)));
299
- int key = keyMap.get("Key");
300
- keyMap.put("Key", ++key);
301
- }
302
- }
303
- builder.setTimestamp(colNum, reader.getTimestamp(column));
304
- }
305
- }
306
-
307
- private void add_builder_for_new_column(int colNum, String newlyAddedColumnType, String matchedData, Boolean isDataMatched) {
308
- try{
309
- if (newlyAddedColumnType.equalsIgnoreCase("string")) {
310
- if (isDataMatched) {
311
- builder.setString(colNum, matchedData);
312
- } else {
313
- builder.setString(colNum, "");
314
- }
315
-
316
- } else if (newlyAddedColumnType.equalsIgnoreCase("long")) {
317
- if (isDataMatched) {
318
- if (matchedData.length() == 0) {
319
- builder.setLong(colNum, 0);
320
- }else{
321
- builder.setLong(colNum, Long.parseLong(matchedData));
322
- }
323
- } else {
324
- builder.setLong(colNum, 0);
325
- }
326
-
327
- } else if (newlyAddedColumnType.equalsIgnoreCase("double")) {
328
- if (isDataMatched) {
329
- if (matchedData.length() == 0) {
330
- builder.setDouble(colNum, 0.0);
331
- }else{
332
- builder.setDouble(colNum, Double.parseDouble(matchedData));
333
- }
334
- } else {
335
- builder.setDouble(colNum, 0.0);
336
- }
337
- } else if (newlyAddedColumnType.equalsIgnoreCase("boolean")) {
338
- if (isDataMatched) {
339
- if (matchedData.length() == 0) {
340
- builder.setNull(colNum);
341
- }else{
342
- builder.setBoolean(colNum, Boolean.parseBoolean(matchedData));
343
- }
344
- } else {
345
- builder.setNull(colNum);
346
- }
347
- } else if (newlyAddedColumnType.equalsIgnoreCase("timestamp")) {
348
- if (isDataMatched) {
349
- if (matchedData.length() == 0) {
350
- builder.setNull(colNum);
351
- }else{
352
- java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(matchedData);
353
- Instant instant = timestamp.toInstant();
354
- org.embulk.spi.time.Timestamp spiTimeStamp = org.embulk.spi.time.Timestamp.ofInstant(instant);
355
- builder.setTimestamp(colNum, spiTimeStamp);
356
- }
357
- } else {
358
- builder.setNull(colNum);
359
- }
360
- }
361
- }catch (Exception e){
362
- e.printStackTrace();
363
- throw new RuntimeException("Data type could not be cast due to wrong data or issue in typecasting timestamp",e);
364
- }
365
-
366
- }
367
- }
1
+ package org.embulk.filter.mssql_lookup;
2
+
3
+ import com.google.common.base.Optional;
4
+ import com.google.common.collect.ImmutableList;
5
+ import org.embulk.config.*;
6
+ import org.embulk.spi.*;
7
+ import org.embulk.spi.type.Types;
8
+
9
+ import java.sql.Connection;
10
+ import java.sql.ResultSet;
11
+ import java.sql.SQLException;
12
+ import java.sql.Statement;
13
+ import java.time.Instant;
14
+ import java.util.ArrayList;
15
+ import java.util.HashMap;
16
+ import java.util.List;
17
+ import java.util.Map;
18
+
19
+ public class MssqlLookupFilterPlugin
20
+ implements FilterPlugin
21
+ {
22
+ public interface PluginTask
23
+ extends Task
24
+ {
25
+ @Config("host")
26
+ public String getHost();
27
+
28
+ @Config("database")
29
+ public String getDatabase();
30
+
31
+ @Config("table_name")
32
+ public String getTableName();
33
+
34
+ @Config("username")
35
+ public String getUserName();
36
+
37
+ @Config("password")
38
+ public String getPassword();
39
+
40
+ @Config("mapping_from")
41
+ public List<String> getMappingFrom();
42
+
43
+ @Config("mapping_to")
44
+ public List<String> getMappingTo();
45
+
46
+ @Config("new_columns")
47
+ public SchemaConfig getNewColumns();
48
+
49
+ @Config("driver_path")
50
+ @ConfigDefault("null")
51
+ public java.util.Optional<String> getDriverPath();
52
+
53
+ @Config("driver_class")
54
+ @ConfigDefault("null")
55
+ public Optional<String> getDriverClass();
56
+
57
+ @Config("schemaName")
58
+ @ConfigDefault("null")
59
+ public Optional<String> getSchemaName();
60
+
61
+ }
62
+
63
+ @Override
64
+ public void transaction(ConfigSource config, Schema inputSchema,
65
+ FilterPlugin.Control control)
66
+ {
67
+ PluginTask task = config.loadConfig(PluginTask.class);
68
+
69
+ List<String> inputColumns = task.getMappingFrom();
70
+ List<String> keyColumns = task.getMappingTo();
71
+ if(inputColumns.size()!=keyColumns.size()){
72
+ throw new RuntimeException("Number of mapping_from columns must be exactly equals to number of mapping_to columns");
73
+ }
74
+
75
+ Schema outputSchema = inputSchema;
76
+
77
+ ImmutableList.Builder<Column> builder = ImmutableList.builder();
78
+ int i = 0;
79
+ for (Column inputColumn : inputSchema.getColumns()) {
80
+ Column outputColumn = new Column(i++, inputColumn.getName(), inputColumn.getType());
81
+ builder.add(outputColumn);
82
+ }
83
+
84
+ for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
85
+ builder.add(columnConfig.toColumn(i++));
86
+ }
87
+ outputSchema = new Schema(builder.build());
88
+
89
+ control.run(task.dump(), outputSchema);
90
+ }
91
+
92
+ @Override
93
+ public PageOutput open(TaskSource taskSource, Schema inputSchema,
94
+ Schema outputSchema, PageOutput output)
95
+ {
96
+ PluginTask task = taskSource.loadTask(PluginTask.class);
97
+ Map<String, List<String>> map = new HashMap<>();
98
+ try {
99
+ map = getKeyValueMap(task);
100
+ } catch (SQLException e) {
101
+ e.printStackTrace();
102
+ }
103
+ PageReader pageReader = new PageReader(inputSchema);
104
+ return new MyOutput(pageReader, inputSchema, outputSchema, output, task, map);
105
+ }
106
+ private Map<String, List<String>> getKeyValueMap(PluginTask task) throws SQLException {
107
+ Map<String, List<String>> map = new HashMap<>();
108
+ Connection con = DatabaseConnection.getConnection(task);
109
+ try {
110
+ List<String> targetColumns = task.getMappingTo();
111
+ List<String> newColumns = new ArrayList<>();
112
+
113
+ for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
114
+ newColumns.add(columnConfig.getName());
115
+ }
116
+
117
+ String query = "select ";
118
+ String columnNeedsToBeFetched = "";
119
+ for (int i = 0; i < targetColumns.size(); i++) {
120
+ columnNeedsToBeFetched += targetColumns.get(i) + ",";
121
+ }
122
+ for (int i = 0; i < newColumns.size(); i++) {
123
+ if (i != newColumns.size() - 1) {
124
+ columnNeedsToBeFetched += newColumns.get(i) + ",";
125
+ } else {
126
+ columnNeedsToBeFetched += newColumns.get(i);
127
+ }
128
+ }
129
+ if (task.getSchemaName().isPresent()) {
130
+ query += columnNeedsToBeFetched + " from " + task.getSchemaName().get() + "." + task.getTableName();
131
+ }else {
132
+ query += columnNeedsToBeFetched + " from " + task.getTableName();
133
+
134
+ }
135
+ Statement stmt = con.createStatement();
136
+ ResultSet rs = stmt.executeQuery(query);
137
+
138
+ while (rs.next()) {
139
+
140
+ //for key
141
+ String key = "";
142
+ String comp = "";
143
+ for (int i = 0; i < targetColumns.size(); i++) {
144
+ comp = "" + rs.getString(targetColumns.get(i));
145
+ if (comp.equalsIgnoreCase("null")) {
146
+ key += "";
147
+ } else {
148
+ key += rs.getString(targetColumns.get(i));
149
+ }
150
+ if (i != targetColumns.size() - 1) {
151
+ key += ",";
152
+ }
153
+ }
154
+
155
+ //for values
156
+ List<String> keyArray = new ArrayList<>();
157
+ for (int i = 0; i < newColumns.size(); i++) {
158
+ comp = "" + rs.getString(newColumns.get(i));
159
+ if (comp.equalsIgnoreCase("null")) {
160
+ keyArray.add("");
161
+ } else {
162
+ keyArray.add(rs.getString(newColumns.get(i)));
163
+ }
164
+ }
165
+ map.put(key, keyArray);
166
+
167
+ }
168
+ } catch (Exception e) {
169
+ e.printStackTrace();
170
+ } finally {
171
+ con.close();
172
+ }
173
+ return map;
174
+ }
175
+ public static class MyOutput implements PageOutput {
176
+ private PageReader reader;
177
+ private PageBuilder builder;
178
+ private PluginTask task;
179
+ private Schema inputSchema;
180
+ private Map<String, List<String>> keyValuePair;
181
+
182
+ public MyOutput(PageReader pageReader, Schema inputSchema, Schema outputSchema, PageOutput pageOutput, PluginTask task, Map<String, List<String>> keyValuePair) {
183
+ this.reader = pageReader;
184
+ this.builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, pageOutput);
185
+ this.task = task;
186
+ this.inputSchema = inputSchema;
187
+ this.keyValuePair = keyValuePair;
188
+ }
189
+
190
+ @Override
191
+ public void add(Page page) {
192
+ reader.setPage(page);
193
+ List<ColumnConfig> columnConfigList = new ArrayList<>();
194
+ for (ColumnConfig columnConfig : task.getNewColumns().getColumns()) {
195
+ columnConfigList.add(columnConfig);
196
+ }
197
+
198
+ while (reader.nextRecord()) {
199
+
200
+ int colNum = 0;
201
+ List<String> inputColumns = task.getMappingFrom();
202
+ List<String> searchingKeyData = new ArrayList<>();
203
+ Map<String, Integer> keyMap = new HashMap<>();
204
+ keyMap.put("Key", 0);
205
+
206
+ for (Column column : inputSchema.getColumns()) {
207
+ if (reader.isNull(column)) {
208
+ if ((keyMap.get("Key") < inputColumns.size()) && column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
209
+ searchingKeyData.add("");
210
+ int key = keyMap.get("Key");
211
+ keyMap.put("Key", ++key);
212
+ }
213
+ builder.setNull(colNum++);
214
+ } else {
215
+ add_builder(colNum++, column, searchingKeyData, inputColumns, keyMap);
216
+ }
217
+ }
218
+
219
+ String key = "";
220
+ for (int k = 0; k < searchingKeyData.size(); k++) {
221
+ key += searchingKeyData.get(k);
222
+ if (k != searchingKeyData.size() - 1) {
223
+ key += ",";
224
+ }
225
+ }
226
+
227
+ List<String> matchedData = new ArrayList<>();
228
+ if (keyValuePair.containsKey(key)) {
229
+ matchedData = keyValuePair.get(key);
230
+ }
231
+
232
+ if (matchedData.size() == 0) {
233
+ for (int k = 0; k < columnConfigList.size(); k++) {
234
+ add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), "", false);
235
+ colNum++;
236
+ }
237
+ } else {
238
+ for (int k = 0; k < columnConfigList.size(); k++) {
239
+ add_builder_for_new_column(colNum, columnConfigList.get(k).getType().getName(), matchedData.get(k), true);
240
+ colNum++;
241
+ }
242
+ }
243
+ builder.addRecord();
244
+ }
245
+ }
246
+
247
+ @Override
248
+ public void finish() {
249
+ builder.finish();
250
+ }
251
+
252
+ @Override
253
+ public void close() {
254
+ builder.close();
255
+ }
256
+
257
+ private void add_builder(int colNum, Column column, List<String> searchingKeyData, List<String> inputColumns, Map<String, Integer> keyMap) {
258
+ if (Types.STRING.equals(column.getType())) {
259
+ if (keyMap.get("Key") < inputColumns.size()) {
260
+ if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
261
+ searchingKeyData.add(reader.getString(column));
262
+ int key = keyMap.get("Key");
263
+ keyMap.put("Key", ++key);
264
+ }
265
+ }
266
+ builder.setString(colNum, reader.getString(column));
267
+ } else if (Types.BOOLEAN.equals(column.getType())) {
268
+ if (keyMap.get("Key") < inputColumns.size()) {
269
+ if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
270
+ searchingKeyData.add(String.valueOf(reader.getBoolean(column)));
271
+ int key = keyMap.get("Key");
272
+ keyMap.put("Key", ++key);
273
+ }
274
+ }
275
+ builder.setBoolean(colNum, reader.getBoolean(column));
276
+ } else if (Types.DOUBLE.equals(column.getType())) {
277
+ if (keyMap.get("Key") < inputColumns.size()) {
278
+ if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
279
+ searchingKeyData.add(String.valueOf(reader.getDouble(column)));
280
+ int key = keyMap.get("Key");
281
+ keyMap.put("Key", ++key);
282
+ }
283
+ }
284
+ builder.setDouble(colNum, reader.getDouble(column));
285
+ } else if (Types.LONG.equals(column.getType())) {
286
+ if (keyMap.get("Key") < inputColumns.size()) {
287
+ if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
288
+ searchingKeyData.add(String.valueOf(reader.getLong(column)));
289
+ int key = keyMap.get("Key");
290
+ keyMap.put("Key", ++key);
291
+ }
292
+ }
293
+
294
+ builder.setLong(colNum, reader.getLong(column));
295
+ } else if (Types.TIMESTAMP.equals(column.getType())) {
296
+ if (keyMap.get("Key") < inputColumns.size()) {
297
+ if (column.getName().equalsIgnoreCase(inputColumns.get(keyMap.get("Key")))) {
298
+ searchingKeyData.add(String.valueOf(reader.getTimestamp(column)));
299
+ int key = keyMap.get("Key");
300
+ keyMap.put("Key", ++key);
301
+ }
302
+ }
303
+ builder.setTimestamp(colNum, reader.getTimestamp(column));
304
+ }
305
+ }
306
+
307
+ private void add_builder_for_new_column(int colNum, String newlyAddedColumnType, String matchedData, Boolean isDataMatched) {
308
+ try{
309
+ if (newlyAddedColumnType.equalsIgnoreCase("string")) {
310
+ if (isDataMatched) {
311
+ builder.setString(colNum, matchedData);
312
+ } else {
313
+ builder.setString(colNum, "");
314
+ }
315
+
316
+ } else if (newlyAddedColumnType.equalsIgnoreCase("long")) {
317
+ if (isDataMatched) {
318
+ if (matchedData.length() == 0) {
319
+ builder.setLong(colNum, 0);
320
+ }else{
321
+ builder.setLong(colNum, Long.parseLong(matchedData));
322
+ }
323
+ } else {
324
+ builder.setLong(colNum, 0);
325
+ }
326
+
327
+ } else if (newlyAddedColumnType.equalsIgnoreCase("double")) {
328
+ if (isDataMatched) {
329
+ if (matchedData.length() == 0) {
330
+ builder.setDouble(colNum, 0.0);
331
+ }else{
332
+ builder.setDouble(colNum, Double.parseDouble(matchedData));
333
+ }
334
+ } else {
335
+ builder.setDouble(colNum, 0.0);
336
+ }
337
+ } else if (newlyAddedColumnType.equalsIgnoreCase("boolean")) {
338
+ if (isDataMatched) {
339
+ if (matchedData.length() == 0) {
340
+ builder.setNull(colNum);
341
+ }else{
342
+ builder.setBoolean(colNum, Boolean.parseBoolean(matchedData));
343
+ }
344
+ } else {
345
+ builder.setNull(colNum);
346
+ }
347
+ } else if (newlyAddedColumnType.equalsIgnoreCase("timestamp")) {
348
+ if (isDataMatched) {
349
+ if (matchedData.length() == 0) {
350
+ builder.setNull(colNum);
351
+ }else{
352
+ java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(matchedData);
353
+ Instant instant = timestamp.toInstant();
354
+ org.embulk.spi.time.Timestamp spiTimeStamp = org.embulk.spi.time.Timestamp.ofInstant(instant);
355
+ builder.setTimestamp(colNum, spiTimeStamp);
356
+ }
357
+ } else {
358
+ builder.setNull(colNum);
359
+ }
360
+ }
361
+ }catch (Exception e){
362
+ e.printStackTrace();
363
+ throw new RuntimeException("Data type could not be cast due to wrong data or issue in typecasting timestamp",e);
364
+ }
365
+
366
+ }
367
+ }
368
368
  }