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

jshao pushed a commit to branch branch-1.2
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.2 by this push:
     new 43c4b8fef2 [Cherry-pick to branch-1.2] [#10161] test: add UTs w/ 
partioned table in TestCompactionStrategyHandler (#10120) (#10178)
43c4b8fef2 is described below

commit 43c4b8fef2e6b33e3e99023062c23d02f74ddba2
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Mar 4 15:55:59 2026 +0800

    [Cherry-pick to branch-1.2] [#10161] test: add UTs w/ partioned table in 
TestCompactionStrategyHandler (#10120) (#10178)
    
    **Cherry-pick Information:**
    - Original commit: 47b42f759ec9d07eb2094f2671409fcba5414f76
    - Target branch: `branch-1.2`
    - Status: ✅ Clean cherry-pick (no conflicts)
    
    Co-authored-by: Roman Horilyi <[email protected]>
    Co-authored-by: Roman Horilyi <[email protected]>
---
 .../compaction/TestCompactionStrategyHandler.java  | 156 +++++++++++++++++++++
 1 file changed, 156 insertions(+)

diff --git 
a/maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/recommender/handler/compaction/TestCompactionStrategyHandler.java
 
b/maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/recommender/handler/compaction/TestCompactionStrategyHandler.java
index 5e8c545e6b..a236554fa4 100644
--- 
a/maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/recommender/handler/compaction/TestCompactionStrategyHandler.java
+++ 
b/maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/recommender/handler/compaction/TestCompactionStrategyHandler.java
@@ -241,6 +241,162 @@ class TestCompactionStrategyHandler {
     Assertions.assertEquals(midPartition, selected.get(1), "Second highest 
score expected");
   }
 
+  @Test
+  void testEvaluateFiltersOutNonMatchedPartitions() {
+    NameIdentifier tableId = NameIdentifier.of("db", "table");
+    Table tableMetadata = Mockito.mock(Table.class);
+    Mockito.when(tableMetadata.partitioning())
+        .thenReturn(
+            new org.apache.gravitino.rel.expressions.transforms.Transform[] {
+              Transforms.identity("p")
+            });
+    Mockito.when(tableMetadata.columns()).thenReturn(new Column[0]);
+
+    PartitionPath partition1 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "1")));
+    PartitionPath partition2 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "2")));
+    PartitionPath partition3 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "3")));
+    PartitionPath partition4 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "4")));
+    PartitionPath partition5 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "5")));
+    PartitionPath partition6 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "6")));
+
+    Map<PartitionPath, List<StatisticEntry<?>>> partitionStats =
+        Map.of(
+            partition1,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(0L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(1L))),
+            partition2,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(10L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(1L))),
+            partition3,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(999L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(1L))),
+            partition4,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(1000L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(5L))),
+            partition5,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(1001L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(3L))),
+            partition6,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(1100L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(6L))));
+
+    StrategyHandlerContext context =
+        StrategyHandlerContext.builder(tableId, strategy)
+            .withTableMetadata(tableMetadata)
+            .withTableStatistics(List.of())
+            .withPartitionStatistics(partitionStats)
+            .build();
+
+    CompactionStrategyHandler handler = new CompactionStrategyHandler();
+    handler.initialize(context);
+    StrategyEvaluation evaluation = handler.evaluate();
+
+    CompactionJobContext jobContext =
+        (CompactionJobContext) evaluation.jobExecutionContext().orElseThrow();
+    List<PartitionPath> selected = jobContext.getPartitions();
+
+    Assertions.assertEquals(
+        2, selected.size(), "Only partitions with datafile_mse > 1000 should 
be included");
+    Assertions.assertTrue(
+        selected.contains(partition5), "Partition with datafile_mse=1001 
should be included");
+    Assertions.assertTrue(
+        selected.contains(partition6), "Partition with datafile_mse=1100 
should be included");
+    Assertions.assertFalse(
+        selected.contains(partition1), "Partition with datafile_mse=0 should 
be filtered out");
+    Assertions.assertFalse(
+        selected.contains(partition2), "Partition with datafile_mse=10 should 
be filtered out");
+    Assertions.assertFalse(
+        selected.contains(partition3), "Partition with datafile_mse=999 should 
be filtered out");
+    Assertions.assertFalse(
+        selected.contains(partition4), "Partition with datafile_mse=1000 
should be filtered out");
+  }
+
+  @Test
+  void testEvaluateWithNoMatchingPartitions() {
+    NameIdentifier tableId = NameIdentifier.of("db", "table");
+    Table tableMetadata = Mockito.mock(Table.class);
+    Mockito.when(tableMetadata.partitioning())
+        .thenReturn(
+            new org.apache.gravitino.rel.expressions.transforms.Transform[] {
+              Transforms.identity("p")
+            });
+    Mockito.when(tableMetadata.columns()).thenReturn(new Column[0]);
+
+    PartitionPath partition1 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "1")));
+    PartitionPath partition2 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "2")));
+    PartitionPath partition3 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "3")));
+    PartitionPath partition4 = PartitionPath.of(Arrays.asList(new 
PartitionEntryImpl("p", "4")));
+
+    Map<PartitionPath, List<StatisticEntry<?>>> partitionStats =
+        Map.of(
+            partition1,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(0L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(1L))),
+            partition2,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(10L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(2L))),
+            partition3,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(500L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(3L))),
+            partition4,
+            List.of(
+                new StatisticEntryImpl("datafile_mse", 
StatisticValues.longValue(1000L)),
+                new StatisticEntryImpl("delete_file_num", 
StatisticValues.longValue(4L))));
+
+    StrategyHandlerContext context =
+        StrategyHandlerContext.builder(tableId, strategy)
+            .withTableMetadata(tableMetadata)
+            .withTableStatistics(List.of())
+            .withPartitionStatistics(partitionStats)
+            .build();
+
+    CompactionStrategyHandler handler = new CompactionStrategyHandler();
+    handler.initialize(context);
+    StrategyEvaluation evaluation = handler.evaluate();
+
+    Assertions.assertTrue(
+        evaluation.jobExecutionContext().isEmpty(),
+        "No job context should be created for partitioned table with no 
partitions");
+  }
+
+  @Test
+  void testEvaluatePartitionedTableWithNoPartitions() {
+    NameIdentifier tableId = NameIdentifier.of("db", "table");
+    Table tableMetadata = Mockito.mock(Table.class);
+    Mockito.when(tableMetadata.partitioning())
+        .thenReturn(
+            new org.apache.gravitino.rel.expressions.transforms.Transform[] {
+              Transforms.identity("p")
+            });
+    Mockito.when(tableMetadata.columns()).thenReturn(new Column[0]);
+
+    Map<PartitionPath, List<StatisticEntry<?>>> emptyPartitionStats = Map.of();
+
+    StrategyHandlerContext context =
+        StrategyHandlerContext.builder(tableId, strategy)
+            .withTableMetadata(tableMetadata)
+            .withTableStatistics(List.of())
+            .withPartitionStatistics(emptyPartitionStats)
+            .build();
+
+    CompactionStrategyHandler handler = new CompactionStrategyHandler();
+    handler.initialize(context);
+    StrategyEvaluation evaluation = handler.evaluate();
+
+    Assertions.assertTrue(
+        evaluation.jobExecutionContext().isEmpty(),
+        "No job context should be created for partitioned table with no 
partitions");
+  }
+
   private long evaluatePartitionScore(
       NameIdentifier tableId,
       Table tableMetadata,

Reply via email to