You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2020/04/09 13:33:36 UTC
[incubator-iotdb] branch template_example created (now edd75f2)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a change to branch template_example
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.
at edd75f2 add a device template example in session-example
This branch includes the following new commits:
new edd75f2 add a device template example in session-example
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-iotdb] 01/01: add a device template example in
session-example
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch template_example
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit edd75f2cb62125636b5dc8e80d3cae653f5c3322
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Apr 9 21:33:04 2020 +0800
add a device template example in session-example
---
.../main/java/org/apache/iotdb/SessionExample.java | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
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 70b5411..08596b2 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java
+++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
@@ -191,33 +191,51 @@ public class SessionExample {
schema2.registerTimeseries(new Path("root.sg1.d2.s2"), new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE));
schema2.registerTimeseries(new Path("root.sg1.d2.s3"), new MeasurementSchema("s3", TSDataType.INT64, TSEncoding.RLE));
- RowBatch rowBatch2 = schema1.createRowBatch("root.sg1.d2", 100);
-
+ RowBatch rowBatch2 = schema2.createRowBatch("root.sg1.d2", 100);
+
+ Schema schema3 = new Schema();
+ Map<String, MeasurementSchema> template = new HashMap<>();
+ template.put("s1", new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
+ template.put("s2", new MeasurementSchema("s2", TSDataType.INT32, TSEncoding.RLE));
+ schema3.registerDeviceTemplate("template3", template);
+ schema3.extendTemplate("template3", new MeasurementSchema("s3", TSDataType.FLOAT, TSEncoding.RLE));
+ schema3.registerDevice("root.sg1.d3", "template3");
+
+ RowBatch rowBatch3 = schema3.createRowBatch("root.sg1.d3", 100);
+
Map<String, RowBatch> rowBatchMap = new HashMap<>();
rowBatchMap.put("root.sg1.d1", rowBatch1);
rowBatchMap.put("root.sg1.d2", rowBatch2);
+ rowBatchMap.put("root.sg1.d3", rowBatch3);
long[] timestamps1 = rowBatch1.timestamps;
Object[] values1 = rowBatch1.values;
long[] timestamps2 = rowBatch2.timestamps;
Object[] values2 = rowBatch2.values;
+ long[] timestamps3 = rowBatch3.timestamps;
+ Object[] values3 = rowBatch3.values;
for (long time = 0; time < 100; time++) {
int row1 = rowBatch1.batchSize++;
int row2 = rowBatch2.batchSize++;
+ int row3 = rowBatch3.batchSize++;
timestamps1[row1] = time;
timestamps2[row2] = time;
+ timestamps3[row3] = time;
for (int i = 0; i < 3; i++) {
long[] sensor1 = (long[]) values1[i];
sensor1[row1] = i;
long[] sensor2 = (long[]) values2[i];
sensor2[row2] = i;
+ long[] sensor3 = (long[]) values3[i];
+ sensor3[row3] = i;
}
if (rowBatch1.batchSize == rowBatch1.getMaxBatchSize()) {
session.insertMultipleDeviceBatch(rowBatchMap);
rowBatch1.reset();
rowBatch2.reset();
+ rowBatch3.reset();
}
}
@@ -225,6 +243,7 @@ public class SessionExample {
session.insertMultipleDeviceBatch(rowBatchMap);
rowBatch1.reset();
rowBatch2.reset();
+ rowBatch3.reset();
}
}