pierrejeambrun commented on code in PR #44516:
URL: https://github.com/apache/airflow/pull/44516#discussion_r1884100942
##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -572,3 +694,12 @@ def _transform_ti_states(states: list[str] | None) ->
list[TaskInstanceState | N
QueryAssetDagIdPatternSearch = Annotated[
_DagIdAssetReferenceFilter, Depends(_DagIdAssetReferenceFilter().depends)
]
+
+# Variables
+VARIABLE_COLUMN_MAP = {
+ "key": Variable.key,
+ "value": Variable._val,
Review Comment:
I think we need to use the `val` proxy not directly `_val`
##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -146,6 +147,127 @@ def depends_search(value: str | None =
Query(alias=pattern_name, default=None))
return depends_search
+class SearchPatternEnum(Enum):
+ """
+ Enum representing the types of search patterns supported.
+
+ - STARTS_WITH: Matches strings starting with the given value.
+ - ENDS_WITH: Matches strings ending with the given value.
+ - CONTAINS: Matches strings containing the given value.
+ - EQUALS: Matches strings exactly equal to the given value.
+ - NOT_STARTS_WITH: Excludes strings starting with the given value.
+ - NOT_ENDS_WITH: Excludes strings ending with the given value.
+ - NOT_CONTAINS: Excludes strings containing the given value.
+ """
+
+ STARTS_WITH = "starts_with"
+ ENDS_WITH = "ends_with"
+ CONTAINS = "contains"
+ EQUALS = "equals"
+ NOT_STARTS_WITH = "not_starts_with"
+ NOT_ENDS_WITH = "not_ends_with"
+ NOT_CONTAINS = "not_contains"
+
+
+class _AdvancedSearchParam(BaseParam[str]):
+ """Advanced search parameter supporting multiple match types."""
+
+ def __init__(
+ self, attribute: ColumnElement, pattern_type: SearchPatternEnum,
skip_none: bool = True
+ ) -> None:
+ self.attribute: ColumnElement = attribute
+ self.pattern_type: SearchPatternEnum = pattern_type
+ self.value: str | None = None
+ self.skip_none = skip_none
+
+ def set_value(self, value: str | None) -> _AdvancedSearchParam:
+ self.value = value
+ return self
+
+ def to_orm(self, select: Select) -> Select:
+ """Apply the appropriate filter to the SQLAlchemy query based on the
match type."""
+ if self.value is None and self.skip_none:
+ return select
+
+ pattern_map = {
+ SearchPatternEnum.STARTS_WITH: f"{self.value}%",
+ SearchPatternEnum.ENDS_WITH: f"%{self.value}",
+ SearchPatternEnum.CONTAINS: f"%{self.value}%",
+ SearchPatternEnum.EQUALS: self.value,
+ SearchPatternEnum.NOT_STARTS_WITH: f"{self.value}%",
+ SearchPatternEnum.NOT_ENDS_WITH: f"%{self.value}",
+ SearchPatternEnum.NOT_CONTAINS: f"%{self.value}%",
+ }
Review Comment:
I think what we eventually want is the ability to create a full custom query
such as:
I want dags that are in `success` or `running` state, and that have a
`dag_id` that starts with `dag_id_prefix` and with at least 1 tag among [tag1,
tag2].
Its basically being able to create a custom query.
Also I think we need to be able to support 'AND' and 'OR' and maybe
composition (cd1 | cd2) & (cd3).
##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -146,6 +147,127 @@ def depends_search(value: str | None =
Query(alias=pattern_name, default=None))
return depends_search
+class SearchPatternEnum(Enum):
+ """
+ Enum representing the types of search patterns supported.
+
+ - STARTS_WITH: Matches strings starting with the given value.
+ - ENDS_WITH: Matches strings ending with the given value.
+ - CONTAINS: Matches strings containing the given value.
+ - EQUALS: Matches strings exactly equal to the given value.
+ - NOT_STARTS_WITH: Excludes strings starting with the given value.
+ - NOT_ENDS_WITH: Excludes strings ending with the given value.
+ - NOT_CONTAINS: Excludes strings containing the given value.
+ """
+
+ STARTS_WITH = "starts_with"
+ ENDS_WITH = "ends_with"
+ CONTAINS = "contains"
+ EQUALS = "equals"
+ NOT_STARTS_WITH = "not_starts_with"
+ NOT_ENDS_WITH = "not_ends_with"
+ NOT_CONTAINS = "not_contains"
Review Comment:
Yes. We need an endpoint to list possible operations (in, or, and, >=
etc...) and the columns that can be used.
--
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]