embulk-output-embulk_output_domo 0.3.0 → 0.3.1
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 +1 -1
 - data/build.gradle +1 -1
 - data/src/main/java/org/embulk/output/embulk_output_domo/EmbulkOutputDomoOutputPlugin.java +125 -94
 - 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: a43474cd86b39442338ad57734bcc0c70fe123ae
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 05c2e28fecf1292959564790a9c9a141e06292f9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2e41586ca7938d74a76776a589488cb493f873bf452f62fbef6b9012b7092b9e58890a810768e4ff9e2953df0a55db1a1a414dce2a3d33c09f2f18628e04f1f7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a41debd9b92b3febe60154e9a044e3b420315ad6c8f1cc8d846393ddff3199811192188f0550a63f0e34edbc7fea32d13ece05b987f99ca7cf0862d4af181bd2
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -23,7 +23,7 @@ embulk gem install embulk-output-embulk_output_domo 
     | 
|
| 
       23 
23 
     | 
    
         
             
            - **useHttps**: description (boolean, default: `true`)
         
     | 
| 
       24 
24 
     | 
    
         
             
            - **streamName**: description (string, required)
         
     | 
| 
       25 
25 
     | 
    
         
             
            - **column_options**: description (object, default: `Check embulk column options`)
         
     | 
| 
       26 
     | 
    
         
            -
            - **batchSize**: description (integer, default: ` 
     | 
| 
      
 26 
     | 
    
         
            +
            - **batchSize**: description (integer, default: `1000`)
         
     | 
| 
       27 
27 
     | 
    
         
             
            - **quote**: description (string, default: `"\""`)
         
     | 
| 
       28 
28 
     | 
    
         
             
            - **quote_policy**: description (string, default: `MINIMAL`)
         
     | 
| 
       29 
29 
     | 
    
         
             
            - **escape**: description (string, default: `null`)
         
     | 
    
        data/build.gradle
    CHANGED
    
    
| 
         @@ -87,7 +87,7 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       87 
87 
     | 
    
         
             
                private static ArrayList<StringBuilder> allRecords = new ArrayList<StringBuilder>();
         
     | 
| 
       88 
88 
     | 
    
         
             
                private static ArrayList<String> recordsParts = new ArrayList<String>();
         
     | 
| 
       89 
89 
     | 
    
         
             
                private int currentPartCounter = 1;
         
     | 
| 
       90 
     | 
    
         
            -
                 
     | 
| 
      
 90 
     | 
    
         
            +
                public static int totalBatches = 1;
         
     | 
| 
       91 
91 
     | 
    
         
             
                private static int pageReaderCount = 0;
         
     | 
| 
       92 
92 
     | 
    
         
             
                private static String TEMP_DIR = "/tmp/csv/" +RandomStringUtils.randomAlphabetic(10)+"/";
         
     | 
| 
       93 
93 
     | 
    
         
             
                public static int totalRecordsCounter = 0;
         
     | 
| 
         @@ -131,10 +131,6 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       131 
131 
     | 
    
         
             
                    @ConfigDefault("true")
         
     | 
| 
       132 
132 
     | 
    
         
             
                    public boolean getUseHttps();
         
     | 
| 
       133 
133 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
                    @Config("updateMethod")
         
     | 
| 
       135 
     | 
    
         
            -
                    @ConfigDefault("REPLACE")
         
     | 
| 
       136 
     | 
    
         
            -
                    public String getUpdateMethod();
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
134 
     | 
    
         
             
                    @Config("streamName")
         
     | 
| 
       139 
135 
     | 
    
         
             
                    public String getStreamName();
         
     | 
| 
       140 
136 
     | 
    
         | 
| 
         @@ -142,8 +138,9 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       142 
138 
     | 
    
         
             
                    @ConfigDefault("{}")
         
     | 
| 
       143 
139 
     | 
    
         
             
                    Map<String, TimestampColumnOption> getColumnOptions();
         
     | 
| 
       144 
140 
     | 
    
         | 
| 
      
 141 
     | 
    
         
            +
                    // Not used we get data in batches from input plugin, so we can configure there
         
     | 
| 
       145 
142 
     | 
    
         
             
                    @Config("batchSize")
         
     | 
| 
       146 
     | 
    
         
            -
                    @ConfigDefault(" 
     | 
| 
      
 143 
     | 
    
         
            +
                    @ConfigDefault("1000")
         
     | 
| 
       147 
144 
     | 
    
         
             
                    public int getBatchSize();
         
     | 
| 
       148 
145 
     | 
    
         | 
| 
       149 
146 
     | 
    
         
             
                    @Config("quote")
         
     | 
| 
         @@ -162,48 +159,7 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       162 
159 
     | 
    
         
             
                    @ConfigDefault("\"LF\"")
         
     | 
| 
       163 
160 
     | 
    
         
             
                    Newline getNewlineInField();
         
     | 
| 
       164 
161 
     | 
    
         
             
                }
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
                    /**
         
     | 
| 
       167 
     | 
    
         
            -
                     * We need to return domo Schema
         
     | 
| 
       168 
     | 
    
         
            -
                     * e.g. new com.domo.sdk.datasets.model.Schema(Lists.newArrayList(new Column(STRING, "Friend"), new Column(STRING, "Attending")))
         
     | 
| 
       169 
     | 
    
         
            -
                     */
         
     | 
| 
       170 
     | 
    
         
            -
                    ArrayList<com.domo.sdk.datasets.model.Column> domoSchema =  new ArrayList<com.domo.sdk.datasets.model.Column>();
         
     | 
| 
       171 
     | 
    
         
            -
                    for (int i = 0; i < schema.size(); i++) {
         
     | 
| 
       172 
     | 
    
         
            -
                        Column column = schema.getColumn(i);
         
     | 
| 
       173 
     | 
    
         
            -
                        Type type = column.getType();
         
     | 
| 
       174 
     | 
    
         
            -
                        System.out.println("{\n" +
         
     | 
| 
       175 
     | 
    
         
            -
                                "      \"type\" : \""+type.getName().toUpperCase()+"\",\n" +
         
     | 
| 
       176 
     | 
    
         
            -
                                "      \"name\" : \""+column.getName() +"\"\n" +
         
     | 
| 
       177 
     | 
    
         
            -
                                "    },");
         
     | 
| 
       178 
     | 
    
         
            -
                        switch (type.getName()) {
         
     | 
| 
       179 
     | 
    
         
            -
                            case "long":
         
     | 
| 
       180 
     | 
    
         
            -
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.LONG, column.getName()));
         
     | 
| 
       181 
     | 
    
         
            -
                                break;
         
     | 
| 
       182 
     | 
    
         
            -
                            case "double":
         
     | 
| 
       183 
     | 
    
         
            -
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.DOUBLE, column.getName()));
         
     | 
| 
       184 
     | 
    
         
            -
                                break;
         
     | 
| 
       185 
     | 
    
         
            -
                            case "boolean":
         
     | 
| 
       186 
     | 
    
         
            -
                                domoSchema.add(new com.domo.sdk.datasets.model.Column( ColumnType.LONG, column.getName()));
         
     | 
| 
       187 
     | 
    
         
            -
                                break;
         
     | 
| 
       188 
     | 
    
         
            -
                            case "string":
         
     | 
| 
       189 
     | 
    
         
            -
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.STRING, column.getName()));
         
     | 
| 
       190 
     | 
    
         
            -
                                break;
         
     | 
| 
       191 
     | 
    
         
            -
                            case "timestamp":
         
     | 
| 
       192 
     | 
    
         
            -
                                domoSchema.add(new com.domo.sdk.datasets.model.Column( ColumnType.DATETIME, column.getName()));
         
     | 
| 
       193 
     | 
    
         
            -
                                break;
         
     | 
| 
       194 
     | 
    
         
            -
                            default:
         
     | 
| 
       195 
     | 
    
         
            -
                                logger.info("Unsupported type " + type.getName());
         
     | 
| 
       196 
     | 
    
         
            -
                                break;
         
     | 
| 
       197 
     | 
    
         
            -
                        }
         
     | 
| 
       198 
     | 
    
         
            -
                    }
         
     | 
| 
       199 
     | 
    
         
            -
                    if(domoSchema != null && domoSchema.size()>0){
         
     | 
| 
       200 
     | 
    
         
            -
                        return new com.domo.sdk.datasets.model.Schema(domoSchema);
         
     | 
| 
       201 
     | 
    
         
            -
                    }
         
     | 
| 
       202 
     | 
    
         
            -
                    else{
         
     | 
| 
       203 
     | 
    
         
            -
                        logger.error("Cannot create domo schema");
         
     | 
| 
       204 
     | 
    
         
            -
                        throw new RuntimeException("Cannot create domo Schema");
         
     | 
| 
       205 
     | 
    
         
            -
                    }
         
     | 
| 
       206 
     | 
    
         
            -
                }
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
       207 
163 
     | 
    
         | 
| 
       208 
164 
     | 
    
         
             
                @Override
         
     | 
| 
       209 
165 
     | 
    
         
             
                public ConfigDiff transaction(ConfigSource config,
         
     | 
| 
         @@ -217,7 +173,6 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       217 
173 
     | 
    
         
             
                    final String clientSecret = task.getClientSecret();
         
     | 
| 
       218 
174 
     | 
    
         
             
                    final String apiHost = task.getApiHost();
         
     | 
| 
       219 
175 
     | 
    
         
             
                    final boolean useHttps = task.getUseHttps();
         
     | 
| 
       220 
     | 
    
         
            -
                    String updateMethod = task.getUpdateMethod();
         
     | 
| 
       221 
176 
     | 
    
         | 
| 
       222 
177 
     | 
    
         
             
                    try {
         
     | 
| 
       223 
178 
     | 
    
         
             
                        if (client == null) {
         
     | 
| 
         @@ -243,7 +198,6 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       243 
198 
     | 
    
         
             
                            totalBatches = task.getBatchSize();
         
     | 
| 
       244 
199 
     | 
    
         
             
                            File directory = new File(TEMP_DIR);
         
     | 
| 
       245 
200 
     | 
    
         
             
                            if(!directory.exists()) {
         
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
201 
     | 
    
         
             
                                directory.mkdirs();
         
     | 
| 
       248 
202 
     | 
    
         
             
                            }
         
     | 
| 
       249 
203 
     | 
    
         
             
                        }
         
     | 
| 
         @@ -345,17 +299,7 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       345 
299 
     | 
    
         
             
                        this.client = client;
         
     | 
| 
       346 
300 
     | 
    
         
             
                        this.task = task;
         
     | 
| 
       347 
301 
     | 
    
         
             
                        this.schema = schema;
         
     | 
| 
       348 
     | 
    
         
            -
                        this.partPageNum = partNum++;
         
     | 
| 
       349 
302 
     | 
    
         | 
| 
       350 
     | 
    
         
            -
                        try {
         
     | 
| 
       351 
     | 
    
         
            -
                            File directory = new File(TEMP_DIR);
         
     | 
| 
       352 
     | 
    
         
            -
                            if (!directory.exists()) {
         
     | 
| 
       353 
     | 
    
         
            -
                                directory.mkdir();
         
     | 
| 
       354 
     | 
    
         
            -
                            }
         
     | 
| 
       355 
     | 
    
         
            -
                        }
         
     | 
| 
       356 
     | 
    
         
            -
                        catch(Exception ex){
         
     | 
| 
       357 
     | 
    
         
            -
                            System.out.println(ex.getMessage());
         
     | 
| 
       358 
     | 
    
         
            -
                        }
         
     | 
| 
       359 
303 
     | 
    
         
             
                        this.partPageNum = partNum++;
         
     | 
| 
       360 
304 
     | 
    
         
             
                        this.quotePolicy = this.task.getQuotePolicy();
         
     | 
| 
       361 
305 
     | 
    
         
             
                        this.quote = this.task.getQuoteChar() != '\0' ? this.task.getQuoteChar() : '"';
         
     | 
| 
         @@ -366,6 +310,10 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       366 
310 
     | 
    
         
             
                        this.nullString = "";
         
     | 
| 
       367 
311 
     | 
    
         
             
                    }
         
     | 
| 
       368 
312 
     | 
    
         | 
| 
      
 313 
     | 
    
         
            +
                    /**
         
     | 
| 
      
 314 
     | 
    
         
            +
                     * Main Transactional Page that loops
         
     | 
| 
      
 315 
     | 
    
         
            +
                     * @param page
         
     | 
| 
      
 316 
     | 
    
         
            +
                     */
         
     | 
| 
       369 
317 
     | 
    
         
             
                    @Override
         
     | 
| 
       370 
318 
     | 
    
         
             
                    public void add(Page page)
         
     | 
| 
       371 
319 
     | 
    
         
             
                    {
         
     | 
| 
         @@ -487,8 +435,20 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       487 
435 
     | 
    
         
             
                    {
         
     | 
| 
       488 
436 
     | 
    
         
             
                        return Exec.newTaskReport();
         
     | 
| 
       489 
437 
     | 
    
         
             
                    }
         
     | 
| 
       490 
     | 
    
         
            -
             
     | 
| 
       491 
438 
     | 
    
         
             
                }
         
     | 
| 
      
 439 
     | 
    
         
            +
                /************************ H E L P E R   M E T H O D S *****************************/
         
     | 
| 
      
 440 
     | 
    
         
            +
             
     | 
| 
      
 441 
     | 
    
         
            +
                /**
         
     | 
| 
      
 442 
     | 
    
         
            +
                 *
         
     | 
| 
      
 443 
     | 
    
         
            +
                 * @param v String value
         
     | 
| 
      
 444 
     | 
    
         
            +
                 * @param delimiter csv delimeter
         
     | 
| 
      
 445 
     | 
    
         
            +
                 * @param policy enum QuotePolicy
         
     | 
| 
      
 446 
     | 
    
         
            +
                 * @param quote Quote Character
         
     | 
| 
      
 447 
     | 
    
         
            +
                 * @param escape Escape Character
         
     | 
| 
      
 448 
     | 
    
         
            +
                 * @param newline NewLine Character
         
     | 
| 
      
 449 
     | 
    
         
            +
                 * @param nullString Null string
         
     | 
| 
      
 450 
     | 
    
         
            +
                 * @return String
         
     | 
| 
      
 451 
     | 
    
         
            +
                 */
         
     | 
| 
       492 
452 
     | 
    
         
             
                private String setEscapeAndQuoteValue(String v, char delimiter, QuotePolicy policy, char quote, char escape, String newline, String nullString)
         
     | 
| 
       493 
453 
     | 
    
         
             
                {
         
     | 
| 
       494 
454 
     | 
    
         
             
                    StringBuilder escapedValue = new StringBuilder();
         
     | 
| 
         @@ -535,25 +495,41 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       535 
495 
     | 
    
         
             
                        return escapedValue.toString();
         
     | 
| 
       536 
496 
     | 
    
         
             
                    }
         
     | 
| 
       537 
497 
     | 
    
         
             
                }
         
     | 
| 
      
 498 
     | 
    
         
            +
             
     | 
| 
      
 499 
     | 
    
         
            +
                /**
         
     | 
| 
      
 500 
     | 
    
         
            +
                 * Quote a string
         
     | 
| 
      
 501 
     | 
    
         
            +
                 * @param v
         
     | 
| 
      
 502 
     | 
    
         
            +
                 * @param quote
         
     | 
| 
      
 503 
     | 
    
         
            +
                 * @return String
         
     | 
| 
      
 504 
     | 
    
         
            +
                 */
         
     | 
| 
       538 
505 
     | 
    
         
             
                private String setQuoteValue(String v, char quote)
         
     | 
| 
       539 
506 
     | 
    
         
             
                {
         
     | 
| 
       540 
     | 
    
         
            -
             
     | 
| 
       541 
507 
     | 
    
         
             
                    return String.valueOf(quote) + v + quote;
         
     | 
| 
       542 
508 
     | 
    
         
             
                }
         
     | 
| 
       543 
     | 
    
         
            -
             
     | 
| 
       544 
     | 
    
         
            -
             
     | 
| 
       545 
     | 
    
         
            -
             
     | 
| 
       546 
     | 
    
         
            -
             
     | 
| 
       547 
     | 
    
         
            -
             
     | 
| 
       548 
     | 
    
         
            -
             
     | 
| 
       549 
     | 
    
         
            -
             
     | 
| 
       550 
     | 
    
         
            -
             
     | 
| 
       551 
     | 
    
         
            -
             
     | 
| 
       552 
     | 
    
         
            -
             
     | 
| 
      
 509 
     | 
    
         
            +
             
     | 
| 
      
 510 
     | 
    
         
            +
                /**
         
     | 
| 
      
 511 
     | 
    
         
            +
                 * Return a list of all CSV files inside a folder
         
     | 
| 
      
 512 
     | 
    
         
            +
                 * @param searchFolder String
         
     | 
| 
      
 513 
     | 
    
         
            +
                 * @return an Arraylist of File Objects
         
     | 
| 
      
 514 
     | 
    
         
            +
                 */
         
     | 
| 
      
 515 
     | 
    
         
            +
                public static ArrayList<File> loadCSVFiles (String searchFolder) {
         
     | 
| 
      
 516 
     | 
    
         
            +
                    File folder = new File(searchFolder);
         
     | 
| 
      
 517 
     | 
    
         
            +
                    File[] listOfFiles = folder.listFiles();
         
     | 
| 
      
 518 
     | 
    
         
            +
                    ArrayList<File> csvFiles = new ArrayList<File>();
         
     | 
| 
      
 519 
     | 
    
         
            +
             
     | 
| 
      
 520 
     | 
    
         
            +
                    for (File file : listOfFiles) {
         
     | 
| 
      
 521 
     | 
    
         
            +
                        if (file.isFile() && file.getName().indexOf(".csv")>0) {
         
     | 
| 
      
 522 
     | 
    
         
            +
                            csvFiles.add(file);
         
     | 
| 
       553 
523 
     | 
    
         
             
                        }
         
     | 
| 
       554 
524 
     | 
    
         
             
                    }
         
     | 
| 
       555 
     | 
    
         
            -
                    return  
     | 
| 
      
 525 
     | 
    
         
            +
                    return csvFiles;
         
     | 
| 
       556 
526 
     | 
    
         
             
                }
         
     | 
| 
      
 527 
     | 
    
         
            +
             
     | 
| 
      
 528 
     | 
    
         
            +
                /**
         
     | 
| 
      
 529 
     | 
    
         
            +
                 * Stringify an ArrayList of StringBuilder to a  String
         
     | 
| 
      
 530 
     | 
    
         
            +
                 * @param records ArrayList of <StringBuilder>
         
     | 
| 
      
 531 
     | 
    
         
            +
                 * @return String
         
     | 
| 
      
 532 
     | 
    
         
            +
                 */
         
     | 
| 
       557 
533 
     | 
    
         
             
                private String stringify(ArrayList<StringBuilder> records) {
         
     | 
| 
       558 
534 
     | 
    
         
             
                    StringBuilder sb = new StringBuilder();
         
     | 
| 
       559 
535 
     | 
    
         
             
                    for (StringBuilder s : records)
         
     | 
| 
         @@ -563,6 +539,14 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       563 
539 
     | 
    
         
             
                    }
         
     | 
| 
       564 
540 
     | 
    
         
             
                    return sb.toString();
         
     | 
| 
       565 
541 
     | 
    
         
             
                }
         
     | 
| 
      
 542 
     | 
    
         
            +
             
     | 
| 
      
 543 
     | 
    
         
            +
                /**
         
     | 
| 
      
 544 
     | 
    
         
            +
                 * Not used currently. It slices a List of a Templated input to chunkSize
         
     | 
| 
      
 545 
     | 
    
         
            +
                 * @param input List<T>
         
     | 
| 
      
 546 
     | 
    
         
            +
                 * @param chunkSize Int
         
     | 
| 
      
 547 
     | 
    
         
            +
                 * @param <T>
         
     | 
| 
      
 548 
     | 
    
         
            +
                 * @return
         
     | 
| 
      
 549 
     | 
    
         
            +
                 */
         
     | 
| 
       566 
550 
     | 
    
         
             
                public static <T> List<List<T>> batches(List<T> input, int chunkSize) {
         
     | 
| 
       567 
551 
     | 
    
         | 
| 
       568 
552 
     | 
    
         
             
                    int inputSize = input.size();
         
     | 
| 
         @@ -584,15 +568,15 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       584 
568 
     | 
    
         | 
| 
       585 
569 
     | 
    
         
             
                    return chunks;
         
     | 
| 
       586 
570 
     | 
    
         
             
                }
         
     | 
| 
       587 
     | 
    
         
            -
             
     | 
| 
       588 
     | 
    
         
            -
                 
     | 
| 
       589 
     | 
    
         
            -
             
     | 
| 
       590 
     | 
    
         
            -
             
     | 
| 
       591 
     | 
    
         
            -
             
     | 
| 
       592 
     | 
    
         
            -
             
     | 
| 
      
 571 
     | 
    
         
            +
             
     | 
| 
      
 572 
     | 
    
         
            +
                /**
         
     | 
| 
      
 573 
     | 
    
         
            +
                 * Create a List of Zip files. Each zip file will contain a batch of csv files
         
     | 
| 
      
 574 
     | 
    
         
            +
                 * @param sourceFiles A List of Source <Files>
         
     | 
| 
      
 575 
     | 
    
         
            +
                 * @param path string
         
     | 
| 
      
 576 
     | 
    
         
            +
                 * @return List<File>
         
     | 
| 
      
 577 
     | 
    
         
            +
                 */
         
     | 
| 
       593 
578 
     | 
    
         
             
                public static List<File> toGzipFilesUTF8( List<File> sourceFiles, String path){
         
     | 
| 
       594 
579 
     | 
    
         
             
                    List<File> files = new ArrayList<>();
         
     | 
| 
       595 
     | 
    
         
            -
                    int batchMaxCount = 1000;
         
     | 
| 
       596 
580 
     | 
    
         
             
                    int currentCount = 0;
         
     | 
| 
       597 
581 
     | 
    
         
             
                    int remaining = sourceFiles.size();
         
     | 
| 
       598 
582 
     | 
    
         
             
                    ArrayList<File> batchFiles = new ArrayList<File>();
         
     | 
| 
         @@ -600,8 +584,8 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       600 
584 
     | 
    
         
             
                    for (File sourceFile : sourceFiles) {
         
     | 
| 
       601 
585 
     | 
    
         
             
                        currentCount++;
         
     | 
| 
       602 
586 
     | 
    
         
             
                        batchFiles.add(sourceFile);
         
     | 
| 
       603 
     | 
    
         
            -
                        if(currentCount>= 
     | 
| 
       604 
     | 
    
         
            -
                            remaining=remaining- 
     | 
| 
      
 587 
     | 
    
         
            +
                        if(currentCount>=totalBatches || currentCount>=remaining){
         
     | 
| 
      
 588 
     | 
    
         
            +
                            remaining=remaining-totalBatches;
         
     | 
| 
       605 
589 
     | 
    
         
             
                            String zipFileName = sourceFile.getName().replace(".csv", ".zip");
         
     | 
| 
       606 
590 
     | 
    
         
             
                            files.add(toGzipFileUTF8(batchFiles, path + zipFileName));
         
     | 
| 
       607 
591 
     | 
    
         
             
                            // System.out.println("Add file "+sourceFile.getName()+"to zip file name = "+zipFileName+". Current count = "+currentCount +" Total records counter = "+totalRecordsCounter);
         
     | 
| 
         @@ -613,6 +597,13 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       613 
597 
     | 
    
         
             
                    }
         
     | 
| 
       614 
598 
     | 
    
         
             
                    return files;
         
     | 
| 
       615 
599 
     | 
    
         
             
                }
         
     | 
| 
      
 600 
     | 
    
         
            +
             
     | 
| 
      
 601 
     | 
    
         
            +
                /**
         
     | 
| 
      
 602 
     | 
    
         
            +
                 * Read csv Files as UTF-8, convert to String
         
     | 
| 
      
 603 
     | 
    
         
            +
                 * @param csvFiles
         
     | 
| 
      
 604 
     | 
    
         
            +
                 * @param zipFilePath
         
     | 
| 
      
 605 
     | 
    
         
            +
                 * @return a Zip File
         
     | 
| 
      
 606 
     | 
    
         
            +
                 */
         
     | 
| 
       616 
607 
     | 
    
         
             
                public static File toGzipFileUTF8(ArrayList<File> csvFiles, String zipFilePath){
         
     | 
| 
       617 
608 
     | 
    
         
             
                    File outputFile = new File(zipFilePath);
         
     | 
| 
       618 
609 
     | 
    
         
             
                    try {
         
     | 
| 
         @@ -639,6 +630,13 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       639 
630 
     | 
    
         | 
| 
       640 
631 
     | 
    
         
             
                    return outputFile;
         
     | 
| 
       641 
632 
     | 
    
         
             
                }
         
     | 
| 
      
 633 
     | 
    
         
            +
             
     | 
| 
      
 634 
     | 
    
         
            +
                /**
         
     | 
| 
      
 635 
     | 
    
         
            +
                 * Writes a CSV File
         
     | 
| 
      
 636 
     | 
    
         
            +
                 * @param fileContent
         
     | 
| 
      
 637 
     | 
    
         
            +
                 * @param fileName
         
     | 
| 
      
 638 
     | 
    
         
            +
                 * @throws IOException
         
     | 
| 
      
 639 
     | 
    
         
            +
                 */
         
     | 
| 
       642 
640 
     | 
    
         
             
                public static void WriteToFile(String fileContent, String fileName) throws IOException {
         
     | 
| 
       643 
641 
     | 
    
         
             
                    //logger.info("writing csv file to "+fileName);
         
     | 
| 
       644 
642 
     | 
    
         | 
| 
         @@ -660,18 +658,51 @@ public class EmbulkOutputDomoOutputPlugin 
     | 
|
| 
       660 
658 
     | 
    
         
             
                    bw.close();
         
     | 
| 
       661 
659 
     | 
    
         
             
                }
         
     | 
| 
       662 
660 
     | 
    
         | 
| 
       663 
     | 
    
         
            -
                 
     | 
| 
       664 
     | 
    
         
            -
             
     | 
| 
       665 
     | 
    
         
            -
             
     | 
| 
       666 
     | 
    
         
            -
             
     | 
| 
       667 
     | 
    
         
            -
             
     | 
| 
       668 
     | 
    
         
            -
             
     | 
| 
       669 
     | 
    
         
            -
             
     | 
| 
       670 
     | 
    
         
            -
             
     | 
| 
       671 
     | 
    
         
            -
             
     | 
| 
      
 661 
     | 
    
         
            +
                /**
         
     | 
| 
      
 662 
     | 
    
         
            +
                 * Get Domo Schema
         
     | 
| 
      
 663 
     | 
    
         
            +
                 * @param schema
         
     | 
| 
      
 664 
     | 
    
         
            +
                 * @return
         
     | 
| 
      
 665 
     | 
    
         
            +
                 */
         
     | 
| 
      
 666 
     | 
    
         
            +
                public com.domo.sdk.datasets.model.Schema getDomoSchema(Schema schema){
         
     | 
| 
      
 667 
     | 
    
         
            +
                    /**
         
     | 
| 
      
 668 
     | 
    
         
            +
                     * We need to return domo Schema
         
     | 
| 
      
 669 
     | 
    
         
            +
                     * e.g. new com.domo.sdk.datasets.model.Schema(Lists.newArrayList(new Column(STRING, "Friend"), new Column(STRING, "Attending")))
         
     | 
| 
      
 670 
     | 
    
         
            +
                     */
         
     | 
| 
      
 671 
     | 
    
         
            +
                    ArrayList<com.domo.sdk.datasets.model.Column> domoSchema =  new ArrayList<com.domo.sdk.datasets.model.Column>();
         
     | 
| 
      
 672 
     | 
    
         
            +
                    for (int i = 0; i < schema.size(); i++) {
         
     | 
| 
      
 673 
     | 
    
         
            +
                        Column column = schema.getColumn(i);
         
     | 
| 
      
 674 
     | 
    
         
            +
                        Type type = column.getType();
         
     | 
| 
      
 675 
     | 
    
         
            +
                        System.out.println("{\n" +
         
     | 
| 
      
 676 
     | 
    
         
            +
                                "      \"type\" : \""+type.getName().toUpperCase()+"\",\n" +
         
     | 
| 
      
 677 
     | 
    
         
            +
                                "      \"name\" : \""+column.getName() +"\"\n" +
         
     | 
| 
      
 678 
     | 
    
         
            +
                                "    },");
         
     | 
| 
      
 679 
     | 
    
         
            +
                        switch (type.getName()) {
         
     | 
| 
      
 680 
     | 
    
         
            +
                            case "long":
         
     | 
| 
      
 681 
     | 
    
         
            +
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.LONG, column.getName()));
         
     | 
| 
      
 682 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 683 
     | 
    
         
            +
                            case "double":
         
     | 
| 
      
 684 
     | 
    
         
            +
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.DOUBLE, column.getName()));
         
     | 
| 
      
 685 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 686 
     | 
    
         
            +
                            case "boolean":
         
     | 
| 
      
 687 
     | 
    
         
            +
                                domoSchema.add(new com.domo.sdk.datasets.model.Column( ColumnType.LONG, column.getName()));
         
     | 
| 
      
 688 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 689 
     | 
    
         
            +
                            case "string":
         
     | 
| 
      
 690 
     | 
    
         
            +
                                domoSchema.add(new com.domo.sdk.datasets.model.Column(ColumnType.STRING, column.getName()));
         
     | 
| 
      
 691 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 692 
     | 
    
         
            +
                            case "timestamp":
         
     | 
| 
      
 693 
     | 
    
         
            +
                                domoSchema.add(new com.domo.sdk.datasets.model.Column( ColumnType.DATETIME, column.getName()));
         
     | 
| 
      
 694 
     | 
    
         
            +
                                break;
         
     | 
| 
      
 695 
     | 
    
         
            +
                            default:
         
     | 
| 
      
 696 
     | 
    
         
            +
                                logger.info("Unsupported type " + type.getName());
         
     | 
| 
      
 697 
     | 
    
         
            +
                                break;
         
     | 
| 
       672 
698 
     | 
    
         
             
                        }
         
     | 
| 
       673 
     | 
    
         
            -
             
     | 
| 
       674 
     | 
    
         
            -
                     
     | 
| 
       675 
     | 
    
         
            -
             
     | 
| 
      
 699 
     | 
    
         
            +
                    }
         
     | 
| 
      
 700 
     | 
    
         
            +
                    if(domoSchema != null && domoSchema.size()>0){
         
     | 
| 
      
 701 
     | 
    
         
            +
                        return new com.domo.sdk.datasets.model.Schema(domoSchema);
         
     | 
| 
      
 702 
     | 
    
         
            +
                    }
         
     | 
| 
      
 703 
     | 
    
         
            +
                    else{
         
     | 
| 
      
 704 
     | 
    
         
            +
                        logger.error("Cannot create domo schema");
         
     | 
| 
      
 705 
     | 
    
         
            +
                        throw new RuntimeException("Cannot create domo Schema");
         
     | 
| 
      
 706 
     | 
    
         
            +
                    }
         
     | 
| 
       676 
707 
     | 
    
         
             
                }
         
     | 
| 
       677 
708 
     | 
    
         
             
            }
         
     | 
    
        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.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.1
         
     | 
| 
       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-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -67,7 +67,7 @@ files: 
     | 
|
| 
       67 
67 
     | 
    
         
             
            - classpath/commons-io-2.6.jar
         
     | 
| 
       68 
68 
     | 
    
         
             
            - classpath/hamcrest-core-1.3.jar
         
     | 
| 
       69 
69 
     | 
    
         
             
            - classpath/okio-1.12.0.jar
         
     | 
| 
       70 
     | 
    
         
            -
            - classpath/embulk-output-embulk_output_domo-0.3. 
     | 
| 
      
 70 
     | 
    
         
            +
            - classpath/embulk-output-embulk_output_domo-0.3.1.jar
         
     | 
| 
       71 
71 
     | 
    
         
             
            homepage: https://github.com/alexopoulos7/embulk-output-embulk_output_domo
         
     | 
| 
       72 
72 
     | 
    
         
             
            licenses:
         
     | 
| 
       73 
73 
     | 
    
         
             
            - MIT
         
     |