clintropolis opened a new pull request #9161: refactor numeric first/last aggregators to fix null handling bugs URL: https://github.com/apache/druid/pull/9161 ### Description I did some additional digging related to findings of #9154 and #9159, and managed to hit an npe while sorting a top-n query by a 'long first' aggregator. Checking out the comparators, I assumed it had similar issues to #9159 and would be a quick/simple change, but how ever wrong I was. It turns out, the 'first'/'last' family of aggregators was building on top of `NullableNumericAggregatorFactory`, following #8834, though the lack of correct SQL compatible null handling definitely predates that change. Anyway, the problem with using `NullableNumericAggregatorFactory` is that the 'first'/'last' aggregators aren't aggregating numbers, but rather a complex type of a `SerializablePair` containing the timestamp and the number column value. This would make the aggregator result for a row itself be null rather than a pair containing the timestamp and the null right hand side value, which caused all sorts of funny business down the line when sorting or combining values. For a solution, I did some heavy refactoring, pulling out `NumericFirstAggregator`, `NumericFirstBufferAggregator`, `NumericLastAggregator`, and `NumericLastBufferAggregator`. Further refactoring could likely pull out an additional base type between the first and last aggs and buffer aggs, because the only differences is the time comparison and the initial time values, but it gets kind of messy because they aren't in the same package... Anyway, common code for tracking if the current value is null for on heap and buffer aggs is in these types, and so on and so forth, comparators fixed up, tests added, and so on, so I _think_ these aggs should now handle null numbers correctly. <hr> This PR has: - [x] been self-reviewed. - [ ] added documentation for new or modified features or behaviors. - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links. - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader. - [x] added unit tests or modified existing tests to cover new code paths. - [ ] added integration tests. - [x] been tested in a test Druid cluster.
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
