code: def all_subdag_tasks_query(
      sub_dag_run_ids: list[str],
      session: SASession,
      state: TaskInstanceState,
      confirmed_dates: Iterable[datetime],
  ):
      """Get *all* tasks of the sub dags."""
      qry_sub_dag = (
          select(TaskInstance)
          .where(
              TaskInstance.dag_id.in_(sub_dag_run_ids),
              TaskInstance.execution_date.in_(confirmed_dates),
          )
          .where(
              or_(
                  TaskInstance.state.is_(None),
                  TaskInstance.state != state,
              )
          )
      )
      return qry_sub_dag
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Collection, Iterable, Iterator, NamedTuple
  from sqlalchemy import or_, select
  from sqlalchemy.orm import lazyload
  from airflow.models.dagrun import DagRun
  from airflow.models.taskinstance import TaskInstance
  from airflow.operators.subdag import SubDagOperator
  from airflow.utils import timezone
  from airflow.utils.helpers import exactly_one
  from airflow.utils.session import NEW_SESSION, provide_session
  from airflow.utils.state import DagRunState, State, TaskInstanceState
  from airflow.utils.types import DagRunType
label_desc: Use image node_id 3 for calling a global function with example usage: all_subdag_tasks_query(sub_dag_run_ids, session, state, confirmed_dates) and returns: qry_sub_dag