dkranchii opened a new pull request, #19922: URL: https://github.com/apache/pinot/pull/19922
A large `LIMIT` and `OFFSET` wrapped to a negative int, which reached `new PriorityQueue<>(negative)` and failed the query with an `IllegalArgumentException` instead of returning a result. Both query engines were affected. Added `QueryContext#getLimitPlusOffset`, which saturates at `Integer.MAX_VALUE` using Guava's `IntMath.saturatedAdd`, and routed the single-stage sites through it: `SelectionOrderByOperator`, `LinearSelectionOrderByOperator`, `MinMaxValueBasedSelectionOrderByCombineOperator`, `SelectionOrderByResultsBlockMerger`, `SelectionQuerySegmentPruner` and `SelectionOperatorService`. `SortOperator.create` saturates `fetch + offset` for the multi-stage engine. A bound of `Integer.MAX_VALUE` is safe downstream: queue and list capacities are all clamped by `MAX_ROW_HOLDER_INITIAL_CAPACITY`, and `mergeWithOrdering` bounds its merge count by the actual row counts. `PinotLogicalAggregateRule.getGroupTrimLimit` already clamps the same sum the same way. Not every site threw, which is why the new tests assert on rows rather than only on the absence of an exception: | Site | Old behavior on overflow | |---|---| | `SelectionOrderByOperator`, `SortOperator`, `SelectionOperatorService` n-way merge | `IllegalArgumentException` from `new PriorityQueue<>(negative)` | | `SelectionOperatorService#processSingleDataTable` | `end` went negative, so the result window was empty | | `SelectionQuerySegmentPruner` | Negative remaining-doc budget, so the first segment hit the "already have enough" branch | Regression tests: `SortOperatorTest#shouldSaturateFetchPlusOffsetOnOverflow`, `SelectionOrderByOperatorTest#testLargeLimitPlusOffsetDoesNotOverflow`, `SelectionOperatorServiceTest#testReduceWithOrderingWhenLimitPlusOffsetOverflows` (covers both the single-table and n-way-merge paths), and `SelectionQuerySegmentPrunerTest#testSelectionOrderByWithLimitPlusOffsetOverflow`. ### Labels bugfix -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
