iotdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hao...@apache.org
Subject [iotdb] branch master updated: fix importCSVTool import directory bug & encode bug (#2613)
Date Thu, 18 Feb 2021 03:51:31 GMT
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 5f34a56  fix importCSVTool import directory bug & encode bug (#2613)
5f34a56 is described below

commit 5f34a5663ef47655db2f0189e390f95abd6cea4f
Author: chaow <ccgowork@163.com>
AuthorDate: Thu Feb 18 11:51:09 2021 +0800

    fix importCSVTool import directory bug & encode bug (#2613)
---
 .../main/java/org/apache/iotdb/tool/ImportCsv.java  | 21 +++++++++------------
 .../iotdb/jdbc/AbstractIoTDBJDBCResultSet.java      |  1 +
 .../org/apache/iotdb/tsfile/utils/PublicBAOS.java   |  2 ++
 3 files changed, 12 insertions(+), 12 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 91af958..7a94ded 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
@@ -20,16 +20,19 @@ package org.apache.iotdb.tool;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+
 import jline.console.ConsoleReader;
 import me.tongfei.progressbar.ProgressBar;
 import org.apache.commons.cli.CommandLine;
@@ -94,6 +97,7 @@ public class ImportCsv extends AbstractCsvTool {
   /**
    * Data from csv To tsfile.
    */
+  @SuppressWarnings("squid:S1135")
   private static void loadDataFromCSV(File file) {
     int fileLine;
     try {
@@ -103,8 +107,8 @@ public class ImportCsv extends AbstractCsvTool {
       return;
     }
     System.out.println("Start to import data from: " + file.getName());
-    try (BufferedReader br = new BufferedReader(new FileReader(file));
-        ProgressBar pb = new ProgressBar("Import from: " + file.getName(), fileLine)) {
+    try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),
StandardCharsets.UTF_8));
+         ProgressBar pb = new ProgressBar("Import from: " + file.getName(), fileLine)) {
       pb.setExtraMessage("Importing...");
       String header = br.readLine();
       String[] cols = splitCsvLine(header);
@@ -160,6 +164,7 @@ public class ImportCsv extends AbstractCsvTool {
           valuesList = new ArrayList<>();
         }
       }
+      // TODO change it to insertTablet, now is slow
       session.insertRecords(devices, times, measurementsList, valuesList);
       System.out.println("Insert csv successfully!");
       pb.stepTo(fileLine);
@@ -169,14 +174,6 @@ public class ImportCsv extends AbstractCsvTool {
       System.out.println("CSV file read exception because: " + e.getMessage());
     } catch (IoTDBConnectionException | StatementExecutionException e) {
       System.out.println("Meet error when insert csv because " + e.getMessage());
-    } finally {
-      try {
-        if (session != null) {
-          session.close();
-        }
-      } catch (IoTDBConnectionException e) {
-        System.out.println("Sql statement can not be closed because: " + e.getMessage());
-      }
     }
   }
 
@@ -339,7 +336,7 @@ public class ImportCsv extends AbstractCsvTool {
 
   private static int getFileLineCount(File file) throws IOException {
     int line;
-    try (LineNumberReader count = new LineNumberReader(new FileReader(file))) {
+    try (LineNumberReader count = new LineNumberReader(new InputStreamReader(new FileInputStream(file),
StandardCharsets.UTF_8))) {
       while (count.skip(Long.MAX_VALUE) > 0) {
         // Loop just in case the file is > Long.MAX_VALUE or skip() decides to not read
the entire file
       }
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/AbstractIoTDBJDBCResultSet.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/AbstractIoTDBJDBCResultSet.java
index e08c618..f77b266 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/AbstractIoTDBJDBCResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/AbstractIoTDBJDBCResultSet.java
@@ -42,6 +42,7 @@ import java.sql.Timestamp;
 import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.iotdb.rpc.IoTDBRpcDataSet;
 import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.service.rpc.thrift.TSIService;
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/PublicBAOS.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/PublicBAOS.java
index 085bcef..2d46af1 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/PublicBAOS.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/utils/PublicBAOS.java
@@ -61,6 +61,7 @@ public class PublicBAOS extends ByteArrayOutputStream {
    * @exception  IOException  if an I/O error occurs.
    */
   @Override
+  @SuppressWarnings("squid:S3551")
   public void writeTo(OutputStream out) throws IOException {
     out.write(buf, 0, count);
   }
@@ -76,6 +77,7 @@ public class PublicBAOS extends ByteArrayOutputStream {
    * reusing the already allocated buffer space.
    */
   @Override
+  @SuppressWarnings("squid:S3551")
   public void reset() {
     count = 0;
   }


Mime
View raw message