uranusjr commented on code in PR #37176:
URL: https://github.com/apache/airflow/pull/37176#discussion_r1480910760


##########
airflow/api_connexion/endpoints/dataset_endpoint.py:
##########
@@ -124,3 +129,148 @@ def get_dataset_events(
     return dataset_event_collection_schema.dump(
         DatasetEventCollection(dataset_events=events, 
total_entries=total_entries)
     )
+
+
+def _get_ddrq(dag_id: str, uri: str, session: Session, before: str | None = 
None) -> DatasetDagRunQueue:
+    """Get DatasetDagRunQueue."""
+    dataset = session.scalar(select(DatasetModel).where(DatasetModel.uri == 
uri))
+    if not dataset:
+        return None
+    dataset_id = dataset.id
+
+    where_clause_conditions = [
+        DatasetDagRunQueue.target_dag_id == dag_id,
+        DatasetDagRunQueue.dataset_id == dataset_id,
+    ]
+    if before is not None:
+        where_clause_conditions.append(DatasetDagRunQueue.created_at < 
format_datetime(before))
+
+    return 
session.scalar(select(DatasetDagRunQueue).where(*where_clause_conditions))

Review Comment:
   This can be done in one single query with inner join. But I don’t know 
exactly how to do it with SQLA off hand.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to