Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -5910,6 +5921,15 @@ private void assertRateQueryUsesIntermediateAggregation(String query) {
}
}

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(
Expand Down
Loading