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

JackieTien97 pushed a commit to branch fix-flaky-rate-intermediate-agg-it
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 1e54da95f998cc80d07113f1c2688a7bbe9ceb6f
Author: JackieTien97 <[email protected]>
AuthorDate: Mon Aug 31 20:22:32 2026 +0800

    Fix flaky PARTIAL/FINAL plan assertion in rateFunctionsNormalTest
    
    assertRateQueryUsesIntermediateAggregation unconditionally required a
    PARTIAL/FINAL aggregation split in the EXPLAIN output. Under randomized
    data partition allocation (the SHUFFLE strategy used by
    IoTDBTableAggregation2IT), all 8 devices of rate_merge_test may
    occasionally land in a single DataRegion, where a SINGLE-step
    aggregation is the correct plan, so the assertion failed sporadically.
    
    Skip the PARTIAL/FINAL check when the plan scans fewer than two
    distinct RegionIds; keep it whenever the data actually spans regions.
---
 .../it/query/recent/IoTDBTableAggregationIT.java     | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
index 44d2278a866..518b3da1fdd 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
@@ -36,6 +36,10 @@ import org.junit.runner.RunWith;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
 import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
@@ -5901,6 +5905,13 @@ public class IoTDBTableAggregationIT {
       try (ResultSet resultSet = statement.executeQuery("EXPLAIN (FORMAT JSON) 
" + query)) {
         Assert.assertTrue(resultSet.next());
         String plan = resultSet.getString(1);
+        // The PARTIAL/FINAL split only exists when the scanned data spans 
multiple DataRegions.
+        // Under randomized partition allocation (e.g. the SHUFFLE strategy 
used by
+        // IoTDBTableAggregation2IT), all devices may occasionally land in one 
single region,
+        // where a SINGLE-step aggregation is the correct plan, so the check 
must be skipped.
+        if (countDistinctRegionIds(plan) < 2) {
+          return;
+        }
         Assert.assertTrue(
             "Expected a PARTIAL aggregation in plan: " + plan, 
plan.contains("PARTIAL"));
         Assert.assertTrue("Expected a FINAL aggregation in plan: " + plan, 
plan.contains("FINAL"));
@@ -5910,6 +5921,15 @@ public class IoTDBTableAggregationIT {
     }
   }
 
+  private static int countDistinctRegionIds(String plan) {
+    Set<String> regionIds = new HashSet<>();
+    Matcher matcher = 
Pattern.compile("\"RegionId\"\\s*:\\s*\"(\\d+)\"").matcher(plan);
+    while (matcher.find()) {
+      regionIds.add(matcher.group(1));
+    }
+    return regionIds.size();
+  }
+
   @Test
   public void rateFunctionsBoundaryTest() {
     tableResultSetEqualTest(

Reply via email to