Add a natural sort key function#90322
Conversation
|
Workflow [PR], commit [21a7727] Summary: ❌
|
7cae1bc to
67c222c
Compare
|
It is the first version of implementation. It has some limitations and considerations described in the description part. I'm happy to explain more about that and go ahead with the improvement suggestion. |
tests/queries/0_stateless/03721_check_natural_sort_key.reference
Outdated
Show resolved
Hide resolved
tests/queries/0_stateless/03721_check_natural_sort_key.reference
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR introduces a new string function naturalSortKey(s) that transforms digit runs inside strings into an order-preserving “natural sort key” so that lexicographic ordering matches human-friendly numeric ordering (e.g., file2 < file10). It also adds a stateless test covering a variety of real-world string patterns and edge cases.
Changes:
- Add
naturalSortKeyfunction implementation insrc/Functions/. - Add stateless SQL test cases exercising numeric segments, leading zeros, multiple numeric runs, unicode, NULL/empty, and long strings.
- Add expected output reference for the new stateless test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/Functions/naturalSortKey.cpp |
Implements naturalSortKey(s) by encoding digit-run lengths and digits into a comparable key; registers the function and its documentation. |
tests/queries/0_stateless/03721_check_natural_sort_key.sql |
Adds coverage-oriented stateless queries that order by naturalSortKey(...) across many representative inputs. |
tests/queries/0_stateless/03721_check_natural_sort_key.reference |
Adds the expected output for the new stateless test. |
|
CI failures seem unrelated: |
afa3066
|
A few comments:
cc @vitlibar |
Comparing with collation, function
We stopped appending a null terminator a while ago (#85063)
For |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
You can now use the natural sort key function as
naturalSortKey(s).Documentation entry for user-facing changes
Details