jason810496 commented on code in PR #58092:
URL: https://github.com/apache/airflow/pull/58092#discussion_r2592427789


##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -185,6 +185,64 @@ def depends(cls, *args: Any, **kwargs: Any) -> Self:
         raise NotImplementedError("Use search_param_factory instead , depends 
is not implemented.")
 
 
+class QueryTITaskGroupDisplayNamePattern(BaseParam[str]):
+    """Task group display name pattern filter - returns all tasks in matching 
groups."""
+
+    def __init__(self, dag=None, skip_none: bool = True):
+        super().__init__(skip_none=skip_none)
+        self.dag = dag
+
+    def to_orm(self, select: Select) -> Select:
+        if self.value is None and self.skip_none:
+            return select
+
+        if self.dag and hasattr(self.dag, "task_group"):
+            task_groups = self.dag.task_group.get_task_group_dict()
+
+            # Pattern matching on both group display name and group_id
+            matching_task_ids = []
+            for group_id, task_group in task_groups.items():
+                if group_id is None:  # Skip root group
+                    continue
+
+                # Check both the display name (label) and the group_id for 
pattern matching
+                display_name = getattr(task_group, "label", None)
+                if (
+                    display_name and self._matches_pattern(display_name, 
self.value)
+                ) or self._matches_pattern(group_id, self.value):
+                    matching_task_ids.extend([task.task_id for task in 
task_group.iter_tasks()])
+
+            if matching_task_ids:
+                return 
select.where(TaskInstance.task_id.in_(matching_task_ids))

Review Comment:
   The pattern search will be used with `LIKE` in SQL statement for the other 
entities. 
   
   
https://github.com/apache/airflow/blob/52526b3f6051357587d4826e993e7fe4515b7876/airflow-core/src/airflow/api_fastapi/common/parameters.py#L173-L176
   
   However, in this case, we are only able to get `SerializedDAG` and not able 
to use SQL to filter on those name with `LIKE`. Would it be better to use 
`FilterOptionEnum.IN` and use `if self.value in display_name` be more 
appropriate? 
   
   cc @pierrejeambrun 



##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -185,6 +185,64 @@ def depends(cls, *args: Any, **kwargs: Any) -> Self:
         raise NotImplementedError("Use search_param_factory instead , depends 
is not implemented.")
 
 
+class QueryTITaskGroupDisplayNamePattern(BaseParam[str]):
+    """Task group display name pattern filter - returns all tasks in matching 
groups."""
+
+    def __init__(self, dag=None, skip_none: bool = True):
+        super().__init__(skip_none=skip_none)
+        self.dag = dag

Review Comment:
   Would it be better to provide a setter for `dag` attribute and add 
validation at `to_orm` to check whether the `dag` attribute is set? Just in 
case we need the same query class in some other place and having a explicit 
setter might be more readable.
   
   ```suggestion
           self.dag: None | SerializedDAG = dag
   ```



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

Reply via email to