You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/08/20 16:45:01 UTC

[incubator-streampipes] branch dev updated: [hotfix] CsvFormat cast value to double when exception by cast to long

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 6bd0a8e  [hotfix] CsvFormat cast value to double when exception by cast to long
6bd0a8e is described below

commit 6bd0a8ee1c581340809ccd084c37ca38301705c2
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Fri Aug 20 18:43:08 2021 +0200

    [hotfix] CsvFormat cast value to double when exception by cast to long
---
 .../streampipes/connect/adapter/format/csv/CsvFormat.java   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/format/csv/CsvFormat.java b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/format/csv/CsvFormat.java
index e0ebe55..96a4a62 100644
--- a/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/format/csv/CsvFormat.java
+++ b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/format/csv/CsvFormat.java
@@ -91,7 +91,13 @@ public class CsvFormat implements IFormat {
             for (int i = 0; i <= arr.length - 1; i++) {
 
                 if (!arr[i].equals("") && StringUtils.isNumeric(arr[i])) {
-                    map.put(keyValues[i], Long.parseLong(arr[i]));
+                    // If there is a number format exception for long, transform it to a dauble
+                    try {
+                        map.put(keyValues[i], Long.parseLong(arr[i]));
+                    } catch (NumberFormatException e) {
+                        // If not a double use string as fallback type
+                        map.put(keyValues[i], Double.parseDouble(arr[i]));
+                    }
                 } else if ("true".equals(arr[i].toLowerCase()) || "false".equals(arr[i].toLowerCase())) {
                     map.put(keyValues[i], Boolean.parseBoolean(arr[i]));
                 } else {
@@ -117,6 +123,11 @@ public class CsvFormat implements IFormat {
         }
     }
 
+    public static void main(String... args) {
+        double d = Long.parseLong("15894399000000000000");
+        System.out.println(d);
+    }
+
     @Override
     public FormatDescription declareModel() {