JackieTien97 opened a new pull request, #18556:
URL: https://github.com/apache/iotdb/pull/18556
## Description
`IoTDBTableAggregation2IT.rateFunctionsNormalTest` (inherited from
`IoTDBTableAggregationIT`) fails sporadically:
```
Expected a PARTIAL aggregation in plan: { ... "Step": "SINGLE" ...
"RegionId": "3", "DeviceNumber": "8" ... }
```
### Root cause
`assertRateQueryUsesIntermediateAggregation` unconditionally requires the
`EXPLAIN (FORMAT JSON)` output of an ungrouped
`rate()/increase()/irate()/delta()` query over `rate_merge_test` to contain a
`PARTIAL`/`FINAL` two-step aggregation. That split only exists when the scanned
data spans more than one DataRegion.
`IoTDBTableAggregation2IT` runs with `data_partition_allocation_strategy =
SHUFFLE`. `PartitionBalancer.shuffleAllocationStrategy` assigns each
(seriesSlot, timeSlot) to a **random** DataRegionGroup, and all 8 rows of
`rate_merge_test` fall into one time partition. So occasionally all 8 devices
land in the same DataRegion; the planner then correctly produces a
`SINGLE`-step aggregation with one `DeviceTableScanNode`, and the assertion
fails even though both the plan and the query result are correct (the result
comparison right before the assertion had already passed).
### Fix
Count the distinct `RegionId` values in the JSON plan first. Skip the
`PARTIAL`/`FINAL` check when the plan scans fewer than two distinct regions (a
`SINGLE` aggregation is the correct plan there), and keep asserting it whenever
the data actually spans multiple regions — which preserves the original intent
of the check in the deterministic base-class environment (`CUSTOM` extension
policy with 2 DataRegions per DataNode).
### Verification
- `IoTDBTableAggregationIT#rateFunctionsNormalTest` and
`IoTDBTableAggregation2IT#rateFunctionsNormalTest` pass locally (TableSimpleIT).
- The region-count regex was verified against the single-region failing plan
shape (count 1 → skip), a multi-region shape (count 2 → assert), and
`"RegionId": "Not Assigned"` (count 0 → skip).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]