iotdb-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-iotdb] jt2594838 commented on a change in pull request #172: Refactor iotdb code for cluster
Date Fri, 10 May 2019 06:11:19 GMT
jt2594838 commented on a change in pull request #172: Refactor iotdb code for cluster
URL: https://github.com/apache/incubator-iotdb/pull/172#discussion_r282747208
 
 

 ##########
 File path: iotdb/src/main/java/org/apache/iotdb/db/metadata/Metadata.java
 ##########
 @@ -67,9 +73,122 @@ public Metadata(Map<String, List<MeasurementSchema>> seriesMap,
     return deviceIdMap;
   }
 
+  /**
+   * combine multiple metadatas
+   */
+  public static Metadata combineMetadatas(Metadata[] metadatas) {
+    Map<String, List<MeasurementSchema>> seriesMap = new HashMap<>();
+    Map<String, List<String>> deviceIdMap = new HashMap<>();
+    Map<String, Map<String, MeasurementSchema>> typeSchemaMap = new HashMap<>();
+
+    if (metadatas == null || metadatas.length == 0) {
+      return new Metadata(seriesMap, deviceIdMap);
+    }
+
+    for (int i = 0; i < metadatas.length; i++) {
+      Map<String, List<MeasurementSchema>> subSeriesMap = metadatas[i].seriesMap;
+      for (Entry<String, List<MeasurementSchema>> entry : subSeriesMap.entrySet())
{
+        Map<String, MeasurementSchema> map;
+        if (typeSchemaMap.containsKey(entry.getKey())) {
+          map = typeSchemaMap.get(entry.getKey());
+        } else {
+          map = new HashMap<>();
+        }
+        entry.getValue().forEach(schema -> map.put(schema.getMeasurementId(), schema));
+        if (!typeSchemaMap.containsKey(entry.getKey())) {
+          typeSchemaMap.put(entry.getKey(), map);
+        }
+      }
+
+      Map<String, List<String>> subDeviceIdMap = metadatas[i].deviceIdMap;
+      for (Entry<String, List<String>> entry : subDeviceIdMap.entrySet()) {
+        List<String> list;
+        if (deviceIdMap.containsKey(entry.getKey())) {
+          list = deviceIdMap.get(entry.getKey());
+        } else {
+          list = new ArrayList<>();
+        }
+        list.addAll(entry.getValue());
+        if (!deviceIdMap.containsKey(entry.getKey())) {
+          deviceIdMap.put(entry.getKey(), list);
+        }
+      }
+    }
+
+    for (Entry<String, Map<String, MeasurementSchema>> entry : typeSchemaMap.entrySet())
{
+      List<MeasurementSchema> list = new ArrayList<>();
+      list.addAll(entry.getValue().values());
+      seriesMap.put(entry.getKey(), list);
+    }
+
+    return new Metadata(seriesMap, deviceIdMap);
+  }
+
   @Override
   public String toString() {
     return seriesMap.toString() + "\n" + deviceIdMap.toString();
   }
 
+  @Override
+  public boolean equals(Object obj) {
+    if(this == obj){
+      return true;
+    }
+    if(obj == null){
+      return false;
+    }
+    if(this.getClass() != obj.getClass()){
+      return false;
+    }
+
+    Metadata metadata = (Metadata) obj;
+    return seriesMapEquals(seriesMap, metadata.seriesMap) && deviceIdMapEquals(deviceIdMap,
metadata.deviceIdMap);
+  }
+
+  /**
+   * only used to check if seriesMap is equal to another seriesMap
+   */
+  private boolean seriesMapEquals(Map<String, List<MeasurementSchema>> map1,
Map<String, List<MeasurementSchema>> map2) {
 
 Review comment:
   What is the difference between your implementation and Map.equals()?
   Do you intend to overwrite how two lists are compared in case that two lists have the same
contents but in a different order? If so, I suggest you explain this in the comment.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message