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 44d2278a8665c..518b3da1fdd21 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 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 @@ private void assertRateQueryUsesIntermediateAggregation(String query) { 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 @@ private void assertRateQueryUsesIntermediateAggregation(String query) { } } + private static int countDistinctRegionIds(String plan) { + Set 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(