You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by yi...@apache.org on 2025/02/21 01:58:31 UTC

(hudi) branch master updated: [HUDI-9059] Fix ordering of getInstantTimes in CompletionTimeQueryViewV2 (#12858)

This is an automated email from the ASF dual-hosted git repository.

yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b205d1e2aa [HUDI-9059] Fix ordering of getInstantTimes in CompletionTimeQueryViewV2 (#12858)
3b205d1e2aa is described below

commit 3b205d1e2aaf415cbc60f8b8328aab31bf21727e
Author: Tim Brown <ti...@onehouse.ai>
AuthorDate: Thu Feb 20 19:58:26 2025 -0600

    [HUDI-9059] Fix ordering of getInstantTimes in CompletionTimeQueryViewV2 (#12858)
---
 .../timeline/TestCompletionTimeQueryView.java      | 22 ++++++++++++++++++++++
 .../versioning/v2/CompletionTimeQueryViewV2.java   |  3 +--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/timeline/TestCompletionTimeQueryView.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/timeline/TestCompletionTimeQueryView.java
index 72c25634a86..db5a112f41c 100644
--- a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/timeline/TestCompletionTimeQueryView.java
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/timeline/TestCompletionTimeQueryView.java
@@ -25,6 +25,7 @@ import org.apache.hudi.common.model.HoodieCommitMetadata;
 import org.apache.hudi.common.model.HoodieTableType;
 import org.apache.hudi.common.model.WriteOperationType;
 import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.log.InstantRange;
 import org.apache.hudi.common.table.timeline.ActiveAction;
 import org.apache.hudi.common.table.timeline.CompletionTimeQueryView;
 import org.apache.hudi.common.table.timeline.HoodieInstant;
@@ -45,6 +46,7 @@ import org.junit.jupiter.api.io.TempDir;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -54,6 +56,7 @@ import static org.apache.hudi.common.testutils.HoodieTestUtils.INSTANT_FILE_NAME
 import static org.apache.hudi.common.testutils.HoodieTestUtils.TIMELINE_FACTORY;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -120,6 +123,25 @@ public class TestCompletionTimeQueryView {
     }
   }
 
+  @Test
+  void testGetInstantTimesWithOnlyEndCompletionTime() throws Exception {
+    String tableName = "testTable";
+    String tablePath = tempFile.getAbsolutePath() + StoragePath.SEPARATOR + tableName;
+    HoodieTableMetaClient metaClient = HoodieTestUtils.init(
+        HoodieTestUtils.getDefaultStorageConf(), tablePath, HoodieTableType.COPY_ON_WRITE, tableName);
+    prepareTimeline(tablePath, metaClient);
+    try (CompletionTimeQueryView view =
+             metaClient.getTimelineLayout().getTimelineFactory().createCompletionTimeQueryView(metaClient, String.format("%08d", 3))) {
+      // Fetch instant matching the completion time provided
+      assertEquals(Collections.singletonList("00000009"), view.getInstantTimes(metaClient.getActiveTimeline(), Option.empty(), Option.of("00001009"), InstantRange.RangeType.CLOSED_CLOSED));
+      // Fetch instant just before the completion time provided
+      assertEquals(Collections.singletonList("00000010"), view.getInstantTimes(metaClient.getActiveTimeline(), Option.empty(), Option.of("00001011"), InstantRange.RangeType.CLOSED_CLOSED));
+      // Fall back case where only archive instants are before the completion time provided
+      assertEquals(Arrays.asList("00000001", "00000002", "00000003", "00000004", "00000005"),
+          view.getInstantTimes(metaClient.getActiveTimeline(), Option.empty(), Option.of("00001005"), InstantRange.RangeType.CLOSED_CLOSED));
+    }
+  }
+
   private String getInstantTimeSetFormattedString(CompletionTimeQueryView view, int completionTime1, int completionTime2) {
     return view.getInstantTimes(String.format("%08d", completionTime1), String.format("%08d", completionTime2),
             s -> String.format("%08d", Integer.parseInt(s) - 1000))
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v2/CompletionTimeQueryViewV2.java b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v2/CompletionTimeQueryViewV2.java
index 939613092e1..8005614c6fd 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v2/CompletionTimeQueryViewV2.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v2/CompletionTimeQueryViewV2.java
@@ -191,7 +191,6 @@ public class CompletionTimeQueryViewV2 implements CompletionTimeQueryView, Seria
   }
 
   @Override
-
   public List<String> getInstantTimes(
       HoodieTimeline timeline,
       Option<String> startCompletionTime,
@@ -256,7 +255,7 @@ public class CompletionTimeQueryViewV2 implements CompletionTimeQueryView, Seria
       // fallback to archived timeline
       return this.instantTimeToCompletionTimeMap.entrySet().stream()
           .filter(entry -> InstantComparison.compareTimestamps(entry.getValue(), LESSER_THAN_OR_EQUALS, endCompletionTime.get()))
-          .map(Map.Entry::getKey).collect(Collectors.toList());
+          .map(Map.Entry::getKey).sorted().collect(Collectors.toList());
     }
 
     if (startFromEarliest) {