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 2019/05/16 08:03:04 UTC

[GitHub] [incubator-iotdb] LeiRui commented on a change in pull request #177: fix unstable unit test and polish ReadOnlyTsFile query logic

LeiRui commented on a change in pull request #177: fix unstable unit test and polish ReadOnlyTsFile query logic
URL: https://github.com/apache/incubator-iotdb/pull/177#discussion_r284583000
 
 

 ##########
 File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java
 ##########
 @@ -207,6 +220,38 @@ public boolean getRightClose() {
     return rightClose;
   }
 
+  /**
+   * Return the union of the given time ranges.
+   *
+   * @param unionCandidates time ranges already sorted in ascending order
+   * @return the union of time ranges
+   */
+  public static List<TimeRange> getUnions(ArrayList<TimeRange> unionCandidates) {
+    ArrayList<TimeRange> unionResult = new ArrayList<>();
+    Iterator<TimeRange> iterator = unionCandidates.iterator();
+    TimeRange range_curr;
+
+    if (!iterator.hasNext()) {
+      return unionResult;
+    } else {
+      TimeRange r = iterator.next();
+      range_curr = new TimeRange(r.getMin(), r.getMax());
+    }
+
+    while (iterator.hasNext()) {
+      TimeRange range_next = iterator.next();
+      if (range_curr.intersects(range_next)) {
+        range_curr.set(Math.min(range_curr.getMin(), range_next.getMin()),
+            Math.max(range_curr.getMax(), range_next.getMax()));
+      } else {
+        unionResult.add(new TimeRange(range_curr.getMin(), range_curr.getMax()));
 
 Review comment:
   No. Have you noticed that the next line changes the contents of the range_curr?

----------------------------------------------------------------
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