iotdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genius...@apache.org
Subject [iotdb] 04/04: change doc
Date Mon, 02 Nov 2020 07:54:10 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 6f9e44b9fe6a1000904cbc171d464dfad9ddf10c
Author: Boris <969032536@qq.com>
AuthorDate: Mon Nov 2 15:53:41 2020 +0800

    change doc
---
 README.md                                          | 22 +++------------------
 README_ZH.md                                       | 23 +++-------------------
 .../main/java/org/apache/iotdb/tool/ExportCsv.java | 23 ++++++++++------------
 .../main/java/org/apache/iotdb/tool/ImportCsv.java |  1 +
 4 files changed, 17 insertions(+), 52 deletions(-)

diff --git a/README.md b/README.md
index be83178..75e562f 100644
--- a/README.md
+++ b/README.md
@@ -334,25 +334,13 @@ After being built, the IoTDB cli is located at the folder "cli/target/iotdb-cli-
 
 ## Usage of import-csv.sh
 
-### Create metadata
-```
-SET STORAGE GROUP TO root.fit.d1;
-SET STORAGE GROUP TO root.fit.d2;
-SET STORAGE GROUP TO root.fit.p;
-CREATE TIMESERIES root.fit.d1.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.d1.s2 WITH DATATYPE=TEXT,ENCODING=PLAIN;
-CREATE TIMESERIES root.fit.d2.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.d2.s3 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.p.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-```
-
 ### An example of import csv file
 
 ```
 Time,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3,root.fit.p.s1
-1,100,'hello',200,300,400
-2,500,'world',600,700,800
-3,900,'IoTDB',1000,1100,1200
+1,100,hello,200,300,400
+2,500,world,600,700,800
+3,900,IoTDB,1000,1100,1200
 ```
 
 ### Run import shell
@@ -364,10 +352,6 @@ Time,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3,root.fit.p.s1
 > tools\import-csv.bat -h <ip> -p <port> -u <username> -pw <password>
-f <xxx.csv>
 ```
 
-### Error data file
-
-`csvInsertError.error`
-
 ## Usage of export-csv.sh
 
 ### Run export shell
diff --git a/README_ZH.md b/README_ZH.md
index e7772bd..e04a154 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -335,26 +335,13 @@ server 可以使用 "ctrl-C" 或者执行下面的脚本:
 
 ## 使用 import-csv.sh
 
-### 创建元数据
-
-```
-SET STORAGE GROUP TO root.fit.d1;
-SET STORAGE GROUP TO root.fit.d2;
-SET STORAGE GROUP TO root.fit.p;
-CREATE TIMESERIES root.fit.d1.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.d1.s2 WITH DATATYPE=TEXT,ENCODING=PLAIN;
-CREATE TIMESERIES root.fit.d2.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.d2.s3 WITH DATATYPE=INT32,ENCODING=RLE;
-CREATE TIMESERIES root.fit.p.s1 WITH DATATYPE=INT32,ENCODING=RLE;
-```
-
 ### 从 csv 文件导入数据的示例
 
 ```
 Time,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3,root.fit.p.s1
-1,100,'hello',200,300,400
-2,500,'world',600,700,800
-3,900,'IoTDB',1000,1100,1200
+1,100,hello,200,300,400
+2,500,world,600,700,800
+3,900,IoTDB,1000,1100,1200
 ```
 
 ### 运行 import shell
@@ -366,10 +353,6 @@ Time,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3,root.fit.p.s1
 > tools\import-csv.bat -h <ip> -p <port> -u <username> -pw <password>
-f <xxx.csv>
 ```
 
-### 错误的数据文件
-
-`csvInsertError.error`
-
 ## 使用 export-csv.sh
 
 ### 运行 export shell
diff --git a/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java b/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
index f30ddbc..881e866 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
@@ -41,8 +41,8 @@ import org.apache.iotdb.cli.AbstractCli;
 import org.apache.iotdb.exception.ArgsErrorException;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
 import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.Session;
 import org.apache.iotdb.session.SessionDataSet;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.read.common.Field;
 import org.apache.iotdb.tsfile.read.common.RowRecord;
 
@@ -111,7 +111,12 @@ public class ExportCsv extends AbstractCsvTool {
 
       String sqlFile = commandLine.getOptionValue(SQL_FILE_ARGS);
       String sql;
-
+      session = new Session(host, Integer.parseInt(port), username, password);
+      try {
+        session.open(false);
+      } catch (IoTDBConnectionException e) {
+        e.printStackTrace();
+      }
       try {
         setTimeZone();
       } catch (IoTDBConnectionException | StatementExecutionException e) {
@@ -246,7 +251,7 @@ public class ExportCsv extends AbstractCsvTool {
         return;
       }
     } catch (IOException e) {
-      System.out.println("Cannot create dump file " + path + "because: " + e.getMessage());
+      System.out.println("Cannot create dump file " + path + " " + "because: " + e.getMessage());
       return;
     }
     System.out.println("Start to export data from sql statement: " + sql);
@@ -322,21 +327,13 @@ public class ExportCsv extends AbstractCsvTool {
       if ("null".equals(fields.get(j).getStringValue())) {
         bw.write(",");
       } else {
-        if(fields.get(j).getDataType() == TSDataType.TEXT) {
-          bw.write("'" + fields.get(j).getBinaryV().toString() + "'" + ",");
-        } else {
-          bw.write(fields.get(j).getStringValue() + ",");
-        }
+        bw.write(fields.get(j).getStringValue() + ",");
       }
     }
     if ("null".equals(fields.get(fields.size() - 1).getStringValue())) {
       bw.write("\n");
     } else {
-      if(fields.get(fields.size() - 1).getDataType() == TSDataType.TEXT) {
-        bw.write("'" + fields.get(fields.size() - 1).getBinaryV().toString() + "'" + "\n");
-      } else {
-        bw.write(fields.get(fields.size() - 1).getStringValue() + "\n");
-      }
+      bw.write(fields.get(fields.size() - 1).getStringValue() + "\n");
     }
   }
 }
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 266add5..2b215d9 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ImportCsv.java
@@ -134,6 +134,7 @@ public class ImportCsv extends AbstractCsvTool {
         cols = line.split(",");
         for(String device: deviceToMeasurementsAndPositions.keySet()) {
           devices.add(device);
+          times.add(Long.parseLong(cols[0]));
           Map<String, Integer> measurementsAndPositions = deviceToMeasurementsAndPositions.get(device);
           List<String> measurements = new ArrayList<>();
           List<String> values = new ArrayList<>();


Mime
View raw message