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 aaeda83e9a [IOTDB-3805] Document and example of TEXT session interface 
(#6645)
aaeda83e9a is described below

commit aaeda83e9a6c3e880d2a6c5bf9d269e490aa0a76
Author: Chen YZ <[email protected]>
AuthorDate: Wed Jul 13 00:03:05 2022 +0800

    [IOTDB-3805] Document and example of TEXT session interface (#6645)
---
 docs/UserGuide/API/Programming-Java-Native-API.md  | 13 ++++++-
 .../UserGuide/API/Programming-Java-Native-API.md   | 11 ++++++
 .../main/java/org/apache/iotdb/SessionExample.java | 44 +++++++++++++++++++++-
 3 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/docs/UserGuide/API/Programming-Java-Native-API.md 
b/docs/UserGuide/API/Programming-Java-Native-API.md
index 247af53d08..ad00cfbd30 100644
--- a/docs/UserGuide/API/Programming-Java-Native-API.md
+++ b/docs/UserGuide/API/Programming-Java-Native-API.md
@@ -325,7 +325,7 @@ Attention: Unsetting the template named 'templateName' from 
node at path 'prefix
 
 ### Data Manipulation Interface (DML Interface)
 
-##### Insert
+#### Insert
 
 It is recommended to use insertTablet to help improve write efficiency.
 
@@ -364,6 +364,17 @@ void insertTablets(Map<String, Tablet> tablet)
 
 * Insert a Record, which contains multiple measurement value of a device at a 
timestamp. This method is equivalent to providing a common interface for 
multiple data types of values. Later, the value can be cast to the original 
type through TSDataType.
 
+  The correspondence between the Object type and the TSDataType type is shown 
in the following table.
+
+  | TSDataType | Object         |
+  | ---------- | -------------- |
+  | BOOLEAN    | Boolean        |
+  | INT32      | Integer        |
+  | INT64      | Long           |
+  | FLOAT      | Float          |
+  | DOUBLE     | Double         |
+  | TEXT       | String, Binary |
+
 ```java
 void insertRecord(String deviceId, long time, List<String> measurements,
    List<TSDataType> types, List<Object> values)
diff --git a/docs/zh/UserGuide/API/Programming-Java-Native-API.md 
b/docs/zh/UserGuide/API/Programming-Java-Native-API.md
index 94c1ed40f2..7072bdca8a 100644
--- a/docs/zh/UserGuide/API/Programming-Java-Native-API.md
+++ b/docs/zh/UserGuide/API/Programming-Java-Native-API.md
@@ -351,6 +351,17 @@ void insertTablets(Map<String, Tablet> tablets)
 
 * 插入一个 Record,一个 Record 是一个设备一个时间戳下多个测点的数据。这里的 value 是 Object 
类型,相当于提供了一个公用接口,后面可以通过 TSDataType 将 value 强转为原类型
 
+  其中,Object 类型与 TSDataType 类型的对应关系如下表所示:
+
+  | TSDataType | Object         |
+  | ---------- | -------------- |
+  | BOOLEAN    | Boolean        |
+  | INT32      | Integer        |
+  | INT64      | Long           |
+  | FLOAT      | Float          |
+  | DOUBLE     | Double         |
+  | TEXT       | String, Binary |
+
 ```java
 void insertRecord(String prefixPath, long time, List<String> measurements,
    List<TSDataType> types, List<Object> values)
diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java 
b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
index b86a4cbcf7..d779086480 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java
+++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
@@ -31,12 +31,15 @@ import org.apache.iotdb.session.util.Version;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.Binary;
 import org.apache.iotdb.tsfile.utils.BitMap;
 import org.apache.iotdb.tsfile.write.record.Tablet;
 import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -78,7 +81,7 @@ public class SessionExample {
       }
     }
 
-    // createTemplate();
+    //     createTemplate();
     createTimeseries();
     createMultiTimeseries();
     insertRecord();
@@ -86,6 +89,7 @@ public class SessionExample {
     //    insertTabletWithNullValues();
     //    insertTablets();
     //    insertRecords();
+    //    insertText();
     //    selectInto();
     //    createAndDropContinuousQueries();
     //    nonQuery();
@@ -597,6 +601,44 @@ public class SessionExample {
     }
   }
 
+  /**
+   * This example shows how to insert data of TSDataType.TEXT. You can use the 
session interface to
+   * write data of String type or Binary type.
+   */
+  private static void insertText() throws IoTDBConnectionException, 
StatementExecutionException {
+    String device = "root.sg1.text";
+    // the first data is String type and the second data is Binary type
+    List<Object> datas = Arrays.asList("String", new Binary("Binary"));
+    // insertRecord example
+    for (int i = 0; i < datas.size(); i++) {
+      // write data of String type or Binary type
+      session.insertRecord(
+          device,
+          i,
+          Collections.singletonList("s1"),
+          Collections.singletonList(TSDataType.TEXT),
+          datas.get(i));
+    }
+
+    // insertTablet example
+    List<MeasurementSchema> schemaList = new ArrayList<>();
+    schemaList.add(new MeasurementSchema("s2", TSDataType.TEXT));
+    Tablet tablet = new Tablet(device, schemaList, 100);
+    for (int i = 0; i < datas.size(); i++) {
+      int rowIndex = tablet.rowSize++;
+      tablet.addTimestamp(rowIndex, i);
+      //  write data of String type or Binary type
+      tablet.addValue(schemaList.get(0).getMeasurementId(), rowIndex, 
datas.get(i));
+    }
+    session.insertTablet(tablet);
+    try (SessionDataSet dataSet = session.executeQueryStatement("select s1, s2 
from " + device)) {
+      System.out.println(dataSet.getColumnNames());
+      while (dataSet.hasNext()) {
+        System.out.println(dataSet.next());
+      }
+    }
+  }
+
   private static void selectInto() throws IoTDBConnectionException, 
StatementExecutionException {
     session.executeNonQueryStatement(
         "select s1, s2, s3 into into_s1, into_s2, into_s3 from root.sg1.d1");

Reply via email to