You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/11/08 08:36:14 UTC

[GitHub] [iotdb] wangchao316 commented on a change in pull request #4331: [IOTDB-1626]TsFile API supports write and register on aligned timeseries

wangchao316 commented on a change in pull request #4331:
URL: https://github.com/apache/iotdb/pull/4331#discussion_r744480415



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/file/header/ChunkHeader.java
##########
@@ -153,6 +153,8 @@ public static ChunkHeader deserializeFrom(InputStream inputStream, byte chunkTyp
       throws IOException {
     // read measurementID
     String measurementID = ReadWriteIOUtils.readVarIntString(inputStream);
+    measurementID =
+        measurementID == null ? "" : measurementID; // measurementID in TimeChunk header is null

Review comment:
       1. Comments should be placed on the top line of code
   2. Why is this parameter set to "" when measurementId is empty? 

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/write/TsFileWriter.java
##########
@@ -151,92 +189,205 @@ protected TsFileWriter(TsFileIOWriter fileWriter, Schema schema, TSFileConfig co
   }
 
   public void registerSchemaTemplate(
-      String templateName, Map<String, IMeasurementSchema> template) {
-    schema.registerSchemaTemplate(templateName, template);
+      String templateName, Map<String, UnaryMeasurementSchema> template, boolean isAligned) {
+    schema.registerSchemaTemplate(templateName, new MeasurementGroup(isAligned, template));
   }
 
-  public void registerDevice(String deviceId, String templateName) {
+  public void registerDevice(String deviceId, String templateName) throws WriteProcessException {
+    if (!schema.getSchemaTemplates().containsKey(templateName)) {
+      throw new WriteProcessException("given template is not existed! " + templateName);
+    }
+    if (schema.getRegisteredTimeseriesMap().containsKey(new Path(deviceId))) {
+      throw new WriteProcessException(
+          "this device "
+              + deviceId
+              + " has been registered, you can only use registerDevice method to register empty device.");
+    }
     schema.registerDevice(deviceId, templateName);
   }
 
-  public void registerTimeseries(Path path, IMeasurementSchema measurementSchema)
-      throws WriteProcessException {
-    if (schema.containsTimeseries(path)) {
-      throw new WriteProcessException("given timeseries has exists! " + path);
+  public void registerTimeseries(Path devicePath, List<UnaryMeasurementSchema> measurementSchemas) {
+    for (UnaryMeasurementSchema schema : measurementSchemas) {
+      try {
+        registerTimeseries(devicePath, schema);
+      } catch (WriteProcessException e) {
+        LOG.error(e.getMessage());

Review comment:
       if exception does not deal,  please print warn log.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/page/TimePageReader.java
##########
@@ -53,12 +54,11 @@ public TimePageReader(PageHeader pageHeader, ByteBuffer pageData, Decoder timeDe
   }
 
   public long[] nexTimeBatch() throws IOException {
-    long[] timeBatch = new long[(int) pageHeader.getStatistics().getCount()];
-    int index = 0;
+    List<Long> timeList = new ArrayList<>();
     while (timeDecoder.hasNext(timeBuffer)) {
-      timeBatch[index++] = timeDecoder.readLong(timeBuffer);
+      timeList.add(timeDecoder.readLong(timeBuffer));
     }
-    return timeBatch;
+    return timeList.stream().mapToLong(t -> t.longValue()).toArray();

Review comment:
       Why is this modification necessary? This modification will cause performance loss, which is equivalent to two iterations. o(n*n)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org