Skip to content

Commit 1e54da9

Browse files
committed
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.
1 parent 7a38e7e commit 1e54da9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
import java.sql.Connection;
3737
import java.sql.ResultSet;
3838
import java.sql.Statement;
39+
import java.util.HashSet;
40+
import java.util.Set;
41+
import java.util.regex.Matcher;
42+
import java.util.regex.Pattern;
3943

4044
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
4145
import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
@@ -5901,6 +5905,13 @@ private void assertRateQueryUsesIntermediateAggregation(String query) {
59015905
try (ResultSet resultSet = statement.executeQuery("EXPLAIN (FORMAT JSON) " + query)) {
59025906
Assert.assertTrue(resultSet.next());
59035907
String plan = resultSet.getString(1);
5908+
// The PARTIAL/FINAL split only exists when the scanned data spans multiple DataRegions.
5909+
// Under randomized partition allocation (e.g. the SHUFFLE strategy used by
5910+
// IoTDBTableAggregation2IT), all devices may occasionally land in one single region,
5911+
// where a SINGLE-step aggregation is the correct plan, so the check must be skipped.
5912+
if (countDistinctRegionIds(plan) < 2) {
5913+
return;
5914+
}
59045915
Assert.assertTrue(
59055916
"Expected a PARTIAL aggregation in plan: " + plan, plan.contains("PARTIAL"));
59065917
Assert.assertTrue("Expected a FINAL aggregation in plan: " + plan, plan.contains("FINAL"));
@@ -5910,6 +5921,15 @@ private void assertRateQueryUsesIntermediateAggregation(String query) {
59105921
}
59115922
}
59125923

5924+
private static int countDistinctRegionIds(String plan) {
5925+
Set<String> regionIds = new HashSet<>();
5926+
Matcher matcher = Pattern.compile("\"RegionId\"\\s*:\\s*\"(\\d+)\"").matcher(plan);
5927+
while (matcher.find()) {
5928+
regionIds.add(matcher.group(1));
5929+
}
5930+
return regionIds.size();
5931+
}
5932+
59135933
@Test
59145934
public void rateFunctionsBoundaryTest() {
59155935
tableResultSetEqualTest(

0 commit comments

Comments
 (0)