mrhhsg opened a new pull request, #71391:
URL: https://github.com/apache/doris/pull/71391

   ### What problem does this PR solve?
   
   Issue Number: None
   
   Related PR: #67628
   
   Cherry-picked from #67628 (commit e429e59bdfcf1e555824867a0ed6190828b5ff3b).
   
   `array_sort` evaluates a user-provided lambda comparator. Such a comparator 
may be inconsistent or non-deterministic and therefore does not necessarily 
satisfy the strict weak ordering required by `std::sort`. Passing it directly 
to `std::sort` can cause a BE crash.
   
   ### Changes
   
   - Replace the standard-library sort in the lambda-based `array_sort` path 
with a length-bounded, bottom-up merge sort. The comparator chooses between 
in-range elements but cannot control loop bounds.
   - Reuse caller-owned `DorisVector` scratch storage across rows. Valid 
strict-weak-order comparators produce a stable sorted result; inconsistent 
comparators produce a permutation with unspecified order.
   - Resolve the backport conflict by retaining branch-4.2's integer comparator 
type/value validation, existing error propagation, and outer-NULL array skip.
   - Include the source PR's sorting utility, unit tests, SQL regression suite, 
and expected output. The expected-output adaptation only removes an extra EOF 
blank line.
   
   ### Release note
   
   Fix a potential BE crash when `array_sort` receives an inconsistent lambda 
comparator.
   
   ### Validation
   
   - BE build: passed (`./build.sh --be -j 48`).
   - FE build: passed (`./build.sh --fe -j 48`); Checkstyle reported zero 
violations.
   - ASAN BE unit tests: 36 passed, zero failures/errors/skips, covering 
`UntrustedComparatorSortTest.*` (9 tests) and `ArrayMapFunctionTest.*` (27 
tests).
   - SQL regression: all 4 suites passed, zero failed/fatal/skipped:
     - `test_array_sort_lambda_comparator`
     - `test_array_sort_comparator_type`
     - `test_nested_array_map`
     - `test_array_map_function`
   - Changed C++ files passed the repository's clang-format runner with 
clang-format 16.0.6. The complete committed diff passed `git diff --check`.
   
   ### Check List (For Author)
   
   - Test:
     - [x] Regression test
     - [x] Unit Test
   - Behavior changed:
     - [x] Yes. Inconsistent comparators no longer rely on the standard-library 
ordering contract; their output order remains unspecified. Valid comparators 
use stable sorting.
   - Does this need documentation?
     - [x] No.


-- 
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]

Reply via email to