hussein-awala commented on code in PR #64610:
URL: https://github.com/apache/airflow/pull/64610#discussion_r3539928223
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -515,6 +516,71 @@ def depends_search(
return depends_search
+class _RegexParam(BaseParam[str]):
+ """
+ Filter using database-level regex matching (regexp_match).
+
+ SQLAlchemy's ``regexp_match`` is supported on PostgreSQL (``~`` operator),
+ MySQL/MariaDB (``REGEXP``), and SQLite (via Python ``re.match``).
+ Note: SQLite uses ``re.match`` semantics (anchored at the start of the
+ string), while PostgreSQL uses ``re.search`` (matches anywhere).
+ """
+
+ def __init__(self, attribute: ColumnElement, skip_none: bool = True) ->
None:
+ super().__init__(skip_none=skip_none)
+ self.attribute: ColumnElement = attribute
+
+ def to_orm(self, select: Select) -> Select:
+ if self.value is None and self.skip_none:
+ return select
+ return select.where(self.attribute.regexp_match(self.value))
+
+ @classmethod
+ def depends(cls, *args: Any, **kwargs: Any) -> Self:
+ raise NotImplementedError("Use regex_param_factory instead, depends is
not implemented.")
+
+
+def _validate_regex_pattern(value: str | None) -> str | None:
+ """Validate that the regex pattern is enabled and syntactically correct."""
+ if value is None:
+ return value
+ if not conf.getboolean("api", "enable_regexp_query_filters"):
+ raise HTTPException(
+ status_code=status.HTTP_400_BAD_REQUEST,
+ detail="Regex query filters are disabled. Set [api]
enable_regexp_query_filters = True to use them.",
+ )
+ try:
+ re.compile(value)
+ except re.error as e:
+ raise HTTPException(
+ status_code=status.HTTP_400_BAD_REQUEST,
+ detail=f"Invalid regular expression: {e}",
+ )
+ return value
+
+
+_DEFAULT_REGEX_DESCRIPTION = (
+ "Regex filter. Uses database-native regex "
+ "(PostgreSQL ~ operator, MySQL REGEXP, SQLite re.match). "
+ "Note: on SQLite, matching is anchored at the start of the string."
+)
Review Comment:
Done. The public description is now generic: "Filter results by matching
this regular expression against the field value." The backend specifics stay in
the internal _RegexParam docstring only, and the OpenAPI/TS descriptions were
regenerated to match.
--
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]