embulk-output-embulk_output_domo 0.1.0 → 0.2.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 +4 -4
- data/README.md +19 -5
- data/build.gradle +1 -1
- data/src/main/java/org/embulk/output/embulk_output_domo/EmbulkOutputDomoOutputPlugin.java +107 -51
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ad85a24723e4f76d4c7acb15571978f78ecde9
|
4
|
+
data.tar.gz: b37e2fe3c7766a2c4faeb8d363e758933ada969c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf28f55db720cde8fc932521b0fae8f32d8be9d7154da7255ccdba63d1ab2266ad1600856b063e2473c5cf7874dad4437bffe08334631f76dffe40274e6b6c64
|
7
|
+
data.tar.gz: 86e84fa082c55f484676c5ca34d2bf3622d0e3530c256706fa6eeeada9b147af1e7d3c731406fe5db9761bcdc95d95e9b56d5023d9500d267fd52d17beaa915b
|
data/README.md
CHANGED
@@ -11,17 +11,31 @@ TODO: Write short description here and build.gradle file.
|
|
11
11
|
|
12
12
|
## Configuration
|
13
13
|
|
14
|
-
- **
|
15
|
-
- **
|
16
|
-
- **
|
14
|
+
- **clientId**: description (string, required)
|
15
|
+
- **clientSecret**: description (string, required)
|
16
|
+
- **apiHost**: description (string, default: `"api.domo.com"`)
|
17
|
+
- **useHttps**: description (boolean, default: `true`)
|
18
|
+
- **streamName**: description (string, required)
|
19
|
+
- **column_options**: description (object, default: `Check embulk column options`)
|
20
|
+
- **batchSize**: description (integer, default: `1000000`)
|
21
|
+
- **quote**: description (string, default: `"\""`)
|
22
|
+
- **quote_policy**: description (string, default: `MINIMAL`)
|
23
|
+
- **escape**: description (string, default: `null`)
|
24
|
+
- **newline_in_field**: description (string, default: `LF`)
|
25
|
+
|
17
26
|
|
18
27
|
## Example
|
19
28
|
|
20
29
|
```yaml
|
21
30
|
out:
|
22
31
|
type: embulk_output_domo
|
23
|
-
|
24
|
-
|
32
|
+
clientId: 209410f4-052a-4a25-8191-3475aecab631
|
33
|
+
clientSecret: 00fac62163e9ccea36de4614473f17e18dbf0c9860e7616007a70949c33dc2d6
|
34
|
+
apiHost: api.domo.com
|
35
|
+
useHttps: true
|
36
|
+
streamName: Daily Metrics Test--Angelos
|
37
|
+
updateMethod: APPEND
|
38
|
+
batchSize: 500
|
25
39
|
```
|
26
40
|
|
27
41
|
|
data/build.gradle
CHANGED
@@ -33,6 +33,8 @@ import com.domo.sdk.streams.model.Execution;
|
|
33
33
|
import com.domo.sdk.streams.model.Stream;
|
34
34
|
import com.domo.sdk.streams.model.StreamRequest;
|
35
35
|
import com.domo.sdk.streams.model.UpdateMethod;
|
36
|
+
import com.domo.sdk.datasets.model.DataSet;
|
37
|
+
import com.domo.sdk.datasets.DataSetClient;
|
36
38
|
import com.domo.sdk.DomoClient;
|
37
39
|
import com.domo.sdk.streams.StreamClient;
|
38
40
|
|
@@ -43,6 +45,7 @@ import static com.domo.sdk.request.Scope.DATA;
|
|
43
45
|
import java.io.IOException;
|
44
46
|
import java.util.List;
|
45
47
|
import java.util.Map;
|
48
|
+
import java.util.HashMap;
|
46
49
|
import java.util.ArrayList;
|
47
50
|
import java.util.Date;
|
48
51
|
import java.text.SimpleDateFormat;
|
@@ -52,7 +55,17 @@ public class EmbulkOutputDomoOutputPlugin
|
|
52
55
|
implements OutputPlugin
|
53
56
|
{
|
54
57
|
private static DomoClient client = null;
|
58
|
+
private static Execution execution = null;
|
59
|
+
private static StreamClient sdsClient = null;
|
60
|
+
private static Stream sds = null;
|
61
|
+
private static TimestampFormatter[] timestampFormatters = null;
|
62
|
+
private int partNum = 1;
|
63
|
+
private int totalRecords = 1;
|
55
64
|
protected static Logger logger;
|
65
|
+
private static ArrayList<StringBuilder> allRecords = new ArrayList<StringBuilder>();
|
66
|
+
private static ArrayList<String> recordsParts = new ArrayList<String>();
|
67
|
+
private int currentPartCounter = 1;
|
68
|
+
private static int totalBatches = 1;
|
56
69
|
|
57
70
|
public enum QuotePolicy
|
58
71
|
{
|
@@ -137,6 +150,10 @@ public class EmbulkOutputDomoOutputPlugin
|
|
137
150
|
for (int i = 0; i < schema.size(); i++) {
|
138
151
|
Column column = schema.getColumn(i);
|
139
152
|
Type type = column.getType();
|
153
|
+
logger.info("{\n" +
|
154
|
+
" \"type\" : \""+type.getName().toUpperCase()+"\",\n" +
|
155
|
+
" \"name\" : \""+column.getName() +"\"\n" +
|
156
|
+
" },");
|
140
157
|
switch (type.getName()) {
|
141
158
|
case "long":
|
142
159
|
domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.LONG, column.getName()));
|
@@ -154,7 +171,7 @@ public class EmbulkOutputDomoOutputPlugin
|
|
154
171
|
domoSchema.add(new com.domo.sdk.datasets.model.Column( ColumnType.DATETIME, column.getName()));
|
155
172
|
break;
|
156
173
|
default:
|
157
|
-
|
174
|
+
logger.info("Unsupported type " + type.getName());
|
158
175
|
break;
|
159
176
|
}
|
160
177
|
}
|
@@ -162,12 +179,12 @@ public class EmbulkOutputDomoOutputPlugin
|
|
162
179
|
return new com.domo.sdk.datasets.model.Schema(domoSchema);
|
163
180
|
}
|
164
181
|
else{
|
165
|
-
logger.error("");
|
182
|
+
logger.error("Cannot create domo schema");
|
166
183
|
throw new RuntimeException("Cannot create domo Schema");
|
167
184
|
}
|
168
|
-
|
169
185
|
}
|
170
186
|
|
187
|
+
|
171
188
|
@Override
|
172
189
|
public ConfigDiff transaction(ConfigSource config,
|
173
190
|
Schema schema, int taskCount,
|
@@ -182,9 +199,9 @@ public class EmbulkOutputDomoOutputPlugin
|
|
182
199
|
final boolean useHttps = task.getUseHttps();
|
183
200
|
String updateMethod = task.getUpdateMethod();
|
184
201
|
|
185
|
-
|
186
202
|
try {
|
187
203
|
if (client == null) {
|
204
|
+
//getDomoSchema(schema);
|
188
205
|
com.domo.sdk.request.Config domoConfig = com.domo.sdk.request.Config.with()
|
189
206
|
.clientId(clientId)
|
190
207
|
.clientSecret(clientSecret)
|
@@ -195,6 +212,16 @@ public class EmbulkOutputDomoOutputPlugin
|
|
195
212
|
.build();
|
196
213
|
|
197
214
|
client = DomoClient.create(domoConfig);
|
215
|
+
sdsClient = client.streamClient();
|
216
|
+
|
217
|
+
List<Stream> searchedSds = sdsClient.search("dataSource.name:" + task.getStreamName());
|
218
|
+
sds = searchedSds.get(0);
|
219
|
+
logger.info("Stream "+ sds);
|
220
|
+
execution = sdsClient.createExecution(sds.getId());
|
221
|
+
logger.info("Created Execution: " + execution);
|
222
|
+
timestampFormatters = Timestamps.newTimestampColumnFormatters(task, schema, task.getColumnOptions());
|
223
|
+
totalBatches = task.getBatchSize();
|
224
|
+
|
198
225
|
}
|
199
226
|
}
|
200
227
|
catch(Exception ex){
|
@@ -220,6 +247,68 @@ public class EmbulkOutputDomoOutputPlugin
|
|
220
247
|
Schema schema, int taskCount,
|
221
248
|
List<TaskReport> successTaskReports)
|
222
249
|
{
|
250
|
+
List<List<StringBuilder>> batchLists = batches(allRecords, totalBatches);
|
251
|
+
int i=1;
|
252
|
+
for(List<StringBuilder> l : batchLists){
|
253
|
+
logger.info("Uploading..."+i +" with records = "+l.size() );
|
254
|
+
sdsClient.uploadDataPart(sds.getId(), execution.getId(), i, stringifyList(l));
|
255
|
+
|
256
|
+
i++;
|
257
|
+
}
|
258
|
+
logger.info("Finished Uploading");
|
259
|
+
//sdsClient.uploadDataPart(sds.getId(), execution.getId(), 1, stringify(allRecords));
|
260
|
+
//Commit Execution
|
261
|
+
Execution committedExecution = sdsClient.commitExecution(sds.getId(), execution.getId());
|
262
|
+
logger.info("Committed Execution: " + committedExecution);
|
263
|
+
}
|
264
|
+
|
265
|
+
private String stringifyList(List<StringBuilder> records){
|
266
|
+
StringBuilder sb = new StringBuilder();
|
267
|
+
for (StringBuilder s : records)
|
268
|
+
{
|
269
|
+
if(s!=null) {
|
270
|
+
sb.append(s);
|
271
|
+
sb.append("\n");
|
272
|
+
}
|
273
|
+
else{
|
274
|
+
logger.info("NULL Found!");
|
275
|
+
}
|
276
|
+
}
|
277
|
+
return sb.toString();
|
278
|
+
}
|
279
|
+
|
280
|
+
private String stringify(ArrayList<StringBuilder> records) {
|
281
|
+
StringBuilder sb = new StringBuilder();
|
282
|
+
for (StringBuilder s : records)
|
283
|
+
{
|
284
|
+
sb.append(s);
|
285
|
+
sb.append("\n");
|
286
|
+
}
|
287
|
+
return sb.toString();
|
288
|
+
}
|
289
|
+
|
290
|
+
|
291
|
+
public static <T> List<List<T>> batches(List<T> input, int chunkSize) {
|
292
|
+
|
293
|
+
int inputSize = input.size();
|
294
|
+
int chunkCount = (int) Math.ceil(inputSize / (double) chunkSize);
|
295
|
+
logger.info("chunkCount = "+chunkCount);
|
296
|
+
|
297
|
+
Map<Integer, List<T>> map = new HashMap<>(chunkCount);
|
298
|
+
List<List<T>> chunks = new ArrayList<>(chunkCount);
|
299
|
+
|
300
|
+
for (int i = 0; i < inputSize; i++) {
|
301
|
+
|
302
|
+
map.computeIfAbsent(i / chunkSize, (ignore) -> {
|
303
|
+
|
304
|
+
List<T> chunk = new ArrayList<>();
|
305
|
+
chunks.add(chunk);
|
306
|
+
return chunk;
|
307
|
+
|
308
|
+
}).add(input.get(i));
|
309
|
+
}
|
310
|
+
|
311
|
+
return chunks;
|
223
312
|
}
|
224
313
|
|
225
314
|
@Override
|
@@ -238,17 +327,18 @@ public class EmbulkOutputDomoOutputPlugin
|
|
238
327
|
private final PageReader pageReader;
|
239
328
|
private DomoClient client;
|
240
329
|
private PluginTask task;
|
241
|
-
|
330
|
+
|
242
331
|
private Schema schema;
|
243
332
|
|
333
|
+
|
244
334
|
public DomoPageOutput(final PageReader pageReader,
|
245
335
|
DomoClient client, PluginTask task, Schema schema)
|
246
336
|
{
|
337
|
+
//logger.info("NEW PAGE CONSTRUCTOR!!");
|
247
338
|
this.pageReader = pageReader;
|
248
339
|
this.client = client;
|
249
340
|
this.task = task;
|
250
341
|
this.schema = schema;
|
251
|
-
this.timestampFormatters = Timestamps.newTimestampColumnFormatters(task, schema, task.getColumnOptions());
|
252
342
|
}
|
253
343
|
|
254
344
|
@Override
|
@@ -256,6 +346,7 @@ public class EmbulkOutputDomoOutputPlugin
|
|
256
346
|
{
|
257
347
|
try {
|
258
348
|
pageReader.setPage(page);
|
349
|
+
//logger.info("NEW PAGE ADD!! " + page);
|
259
350
|
final char delimiter = ',';
|
260
351
|
final String delimiterString = ",";
|
261
352
|
final String nullString = "";
|
@@ -263,34 +354,8 @@ public class EmbulkOutputDomoOutputPlugin
|
|
263
354
|
final char quote = this.task.getQuoteChar() != '\0' ? this.task.getQuoteChar() : '"';
|
264
355
|
final char escape = this.task.getEscapeChar().or(quotePolicy == QuotePolicy.NONE ? '\\' : quote);
|
265
356
|
final String newlineInField = this.task.getNewlineInField().getString();
|
357
|
+
//ArrayList<StringBuilder> records = new ArrayList<StringBuilder>();
|
266
358
|
|
267
|
-
ArrayList<StringBuilder> records = new ArrayList<StringBuilder>();
|
268
|
-
StreamClient sdsClient = client.streamClient();
|
269
|
-
|
270
|
-
//Build DataSet to populate the create stream request
|
271
|
-
CreateDataSetRequest ds = new CreateDataSetRequest();
|
272
|
-
ds.setName(task.getStreamName());
|
273
|
-
ds.setDescription("Embulk Data Set");
|
274
|
-
// ds.setSchema(new com.domo.sdk.datasets.model.Schema(Lists.newArrayList(new Column(STRING, "Friend"), new Column(STRING, "Attending"))));
|
275
|
-
ds.setSchema(getDomoSchema(this.schema));
|
276
|
-
|
277
|
-
//Create Stream
|
278
|
-
StreamRequest sdsRequest = new StreamRequest();
|
279
|
-
sdsRequest.setDataSet(ds);
|
280
|
-
if (this.task.getUpdateMethod() == "REPLACE"){
|
281
|
-
sdsRequest.setUpdateMethod(UpdateMethod.REPLACE);
|
282
|
-
}
|
283
|
-
else{
|
284
|
-
sdsRequest.setUpdateMethod(UpdateMethod.APPEND);
|
285
|
-
}
|
286
|
-
Stream sds = sdsClient.create(sdsRequest);
|
287
|
-
System.out.println("Created:" + sds);
|
288
|
-
|
289
|
-
//Create Execution
|
290
|
-
Execution execution = sdsClient.createExecution(sds.getId());
|
291
|
-
System.out.println("Created Execution: " + execution);
|
292
|
-
int partNum = 1;
|
293
|
-
TimestampFormatter[] tFormatters = this.timestampFormatters;
|
294
359
|
while (pageReader.nextRecord()) {
|
295
360
|
StringBuilder lineBuilder = new StringBuilder();
|
296
361
|
pageReader.getSchema().visitColumns(new ColumnVisitor() {
|
@@ -324,7 +389,7 @@ public class EmbulkOutputDomoOutputPlugin
|
|
324
389
|
addDelimiter(column);
|
325
390
|
if (!pageReader.isNull(column)) {
|
326
391
|
Timestamp value = pageReader.getTimestamp(column);
|
327
|
-
addValue(
|
392
|
+
addValue(timestampFormatters[column.getIndex()].format(value));
|
328
393
|
} else {
|
329
394
|
addNullString();
|
330
395
|
}
|
@@ -369,19 +434,15 @@ public class EmbulkOutputDomoOutputPlugin
|
|
369
434
|
}
|
370
435
|
|
371
436
|
});
|
372
|
-
records.add(lineBuilder);
|
437
|
+
//records.add(lineBuilder);
|
438
|
+
allRecords.add(lineBuilder);
|
439
|
+
//logger.info("Records size = "+ records.size());
|
440
|
+
totalRecords++;
|
441
|
+
}
|
442
|
+
logger.info(" records = " + totalRecords);
|
373
443
|
|
374
|
-
if (records.size() >= this.task.getBatchSize()) {
|
375
|
-
this.executeDomoUpload(partNum, this.stringify(records), sdsClient, sds, execution);
|
376
|
-
partNum++;
|
377
444
|
|
378
|
-
logger.info("Number of processed records: {}", records.size());
|
379
|
-
}
|
380
|
-
}
|
381
445
|
|
382
|
-
//Delete Stream
|
383
|
-
// sdsClient.delete(sds.getId());
|
384
|
-
System.out.println("Deleting Dataset: " + sds);
|
385
446
|
}
|
386
447
|
catch (Exception ex) {
|
387
448
|
throw new RuntimeException(ex);
|
@@ -391,6 +452,7 @@ public class EmbulkOutputDomoOutputPlugin
|
|
391
452
|
@Override
|
392
453
|
public void finish()
|
393
454
|
{
|
455
|
+
|
394
456
|
}
|
395
457
|
|
396
458
|
@Override
|
@@ -414,20 +476,14 @@ public class EmbulkOutputDomoOutputPlugin
|
|
414
476
|
for (StringBuilder s : records)
|
415
477
|
{
|
416
478
|
sb.append(s);
|
417
|
-
logger.info("Appending {}"+s.toString());
|
479
|
+
//logger.info("Appending {}"+s.toString());
|
418
480
|
sb.append("\n");
|
419
481
|
}
|
420
482
|
return sb.toString();
|
421
|
-
|
422
483
|
}
|
423
484
|
|
424
485
|
private void executeDomoUpload(int partNum, String csvInput, StreamClient sdsClient, Stream sds, Execution execution) {
|
425
486
|
sdsClient.uploadDataPart(sds.getId(), execution.getId(), partNum, csvInput);
|
426
|
-
|
427
|
-
//Commit Execution
|
428
|
-
Execution committedExecution = sdsClient.commitExecution(sds.getId(), execution.getId());
|
429
|
-
System.out.println("Committed Execution: " + committedExecution);
|
430
|
-
|
431
487
|
}
|
432
488
|
|
433
489
|
private String setEscapeAndQuoteValue(String v, char delimiter, QuotePolicy policy, char quote, char escape, String newline, String nullString)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-embulk_output_domo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angelos Alexopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,9 +64,9 @@ files:
|
|
64
64
|
- classpath/junit-4.12.jar
|
65
65
|
- classpath/okhttp-3.7.0.jar
|
66
66
|
- classpath/logging-interceptor-3.7.0.jar
|
67
|
+
- classpath/embulk-output-embulk_output_domo-0.2.0.jar
|
67
68
|
- classpath/hamcrest-core-1.3.jar
|
68
69
|
- classpath/okio-1.12.0.jar
|
69
|
-
- classpath/embulk-output-embulk_output_domo-0.1.0.jar
|
70
70
|
homepage: https://github.com/angelosalexopoulos/embulk-output-embulk_output_domo
|
71
71
|
licenses:
|
72
72
|
- MIT
|