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

haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new db24295  [IoTDB-2185] get an exception when parsing the header of CSV 
(#4620)
db24295 is described below

commit db242950c175d1cee7b85f8f76e1d9457d9a1c79
Author: Xuan Ronaldo <[email protected]>
AuthorDate: Tue Dec 28 09:49:27 2021 +0800

    [IoTDB-2185] get an exception when parsing the header of CSV (#4620)
---
 cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java 
b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
index 742b78f..6a2d631 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
@@ -45,6 +45,7 @@ import java.io.InputStreamReader;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -557,7 +558,7 @@ public class ImportCsv extends AbstractCsvTool {
       }
       String[] split = headerName.split("\\.");
       String measurementName = split[split.length - 1];
-      String deviceName = headerName.replace("." + measurementName, "");
+      String deviceName = StringUtils.join(Arrays.copyOfRange(split, 0, 
split.length - 1), '.');
       if (deviceAndMeasurementNames != null) {
         if (!deviceAndMeasurementNames.containsKey(deviceName)) {
           deviceAndMeasurementNames.put(deviceName, new ArrayList<>());
@@ -612,7 +613,6 @@ public class ImportCsv extends AbstractCsvTool {
       SimpleDateFormat format = new SimpleDateFormat(timeFormat);
       try {
         format.parse(time).getTime();
-        System.out.println(timeFormat);
         return format;
       } catch (java.text.ParseException ignored) {
         // do nothing
@@ -654,11 +654,9 @@ public class ImportCsv extends AbstractCsvTool {
    * @return
    */
   private static TSDataType typeInfer(String value) {
-    if (value.contains("\"")) {
-      return TEXT;
-    } else if ("true".equals(value) || "false".equals(value)) {
-      return BOOLEAN;
-    } else if (!value.contains(".")) {
+    if (value.contains("\"")) return TEXT;
+    else if (value.equals("true") || value.equals("false")) return BOOLEAN;
+    else if (!value.contains(".")) {
       try {
         Integer.valueOf(value);
         return INT32;
@@ -671,11 +669,9 @@ public class ImportCsv extends AbstractCsvTool {
         }
       }
     } else {
-      if (Float.valueOf(value).toString().length() == 
Double.valueOf(value).toString().length()) {
+      if (Float.valueOf(value).toString().length() == 
Double.valueOf(value).toString().length())
         return FLOAT;
-      } else {
-        return DOUBLE;
-      }
+      else return DOUBLE;
     }
   }
 

Reply via email to