SameerMesiah97 commented on code in PR #75635:
URL: https://github.com/apache/airflow/pull/75635#discussion_r4503787053
##########
airflow-core/tests/unit/api_fastapi/common/test_parameters.py:
##########
@@ -550,12 +545,108 @@ def run(term: str) -> list[str]:
("z", ["z1", "zz"]),
# Documented trade-off, unchanged: a trailing '_' is stripped, so
'dag_' means 'dag'.
("dag_", ["dagZ1", "dag_9", "dag_99", "dag_abc", "dagz9"]),
+ # Contraction digraph cases (Czech 'ch', Welsh 'ng')
+ ("c", ["cesta", "ch1", "chata"]),
+ ("ch", ["ch1", "chata"]),
+ ("n", ["ng1", "nginx", "nop"]),
+ ("ng", ["ng1", "nginx"]),
],
)
def test_only_values_with_the_prefix_come_back(self, select_names, term,
expected):
assert select_names(term) == expected
[email protected]_test
[email protected]("postgres")
+class TestPrefixSearchContractionCollationsPostgres:
+ """
+ Verify prefix search under ICU collations with contractions on PostgreSQL.
+
+ Contraction collations reorder multi-character sequences:
+ - Czech (``cs-CZ-x-icu``): digraph ``ch`` sorts after ``h`` (between ``h``
and ``i``).
+ - Welsh (``cy-x-icu``): digraph ``ng`` sorts after ``g`` (before ``n``).
+ - Igbo (``ig-x-icu``): digraph ``ch`` sorts before ``c``.
+
+ Under these collations, range bounds (``>=`` or ``<``) miss valid matches:
+ - Upper bound: in Czech, ``chata < 'd'`` is False, so prefix ``c`` misses
``chata``.
+ - Lower bound: in Welsh, ``'ng1' >= 'n'`` is False, so prefix ``n`` misses
``ng1``.
+ - Lower bound: in Igbo, ``'ch1' >= 'c'`` is False, so prefix ``c`` misses
``ch1``.
+
+ The exact ``substr(col, 1, len) = prefix`` check is collation-independent
and
+ returns exactly the rows matching Python's ``str.startswith``.
+ """
+
+ ROWS = [
+ "chata",
+ "cesta",
+ "ch1",
+ "ng1",
+ "nginx",
+ "nop",
+ "Chata",
+ "Cesta",
+ "NG1",
+ "Nginx",
+ "Nop",
+ ]
+
+ COLLATIONS = ["cs-CZ-x-icu", "cy-x-icu", "ig-x-icu"]
+ PREFIXES = ["c", "ch", "n", "ng"]
+
+ @pytest.mark.parametrize("collation", COLLATIONS)
Review Comment:
I see you have parametrized collations in this but could you do something
similar for prefixes as well?
##########
airflow-core/src/airflow/api_fastapi/common/parameters/search.py:
##########
@@ -42,70 +42,42 @@
class _PrefixPatternParam(BaseParam[str], ABC):
"""
- Shared prefix pattern: pipe ``|`` for OR, ``~`` → empty (match all),
Unicode prefix range.
+ Shared prefix pattern: pipe ``|`` for OR, ``~`` → empty (match all), exact
prefix check.
.. note::
- Trailing non-alphanumeric characters in a search term are stripped
before the range
- is computed. A range scan with a punctuation-terminated upper bound is
unsafe under
- PostgreSQL's default locale-aware collation (``en_US.utf8`` sorts
punctuation in a
- way that breaks the range), and additionally stopping the range at an
alphanumeric
- character keeps the upper bound alphanumeric too, so the predicate
stays usable by
- default btree indexes. A user who asks for prefix ``"test_"`` gets
matches starting
- with ``"test"`` — a small over-match trade-off made explicit in the
public
+ Trailing non-alphanumeric characters in a search term are stripped
before the
+ predicate is built. Punctuation-terminated terms are unsafe under
PostgreSQL's
+ default locale-aware collation (``en_US.utf8`` sorts punctuation
unexpectedly),
+ so the term is stripped first. A user who asks for prefix ``"test_"``
gets matches
+ starting with ``"test"`` — a small over-match trade-off made explicit
in the public
``*_prefix_pattern`` query-param description.
Review Comment:
This docstring could be slightly more accurate. Please see the below:
```
.. note::
Trailing non-alphanumeric characters in a search term are stripped to
preserve existing prefix-search behaviour. A user who asks for prefix
``test_`` gets matches starting with ``test`` — a small over-match
trade-off made explicit in the public ``*_prefix_pattern`` query-param
description.
```
--
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]