amoghrajesh commented on code in PR #45960:
URL: https://github.com/apache/airflow/pull/45960#discussion_r1975159715


##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -445,6 +466,12 @@ def assets(self) -> AssetOperations:
         """Operations related to Assets."""
         return AssetOperations(self)
 
+    @lru_cache()  # type: ignore[misc]
+    @property

Review Comment:
   Sure yeah, doesnt matter in this one



##########
airflow/api_fastapi/execution_api/routes/asset_events.py:
##########
@@ -0,0 +1,81 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from typing import Annotated
+
+from fastapi import Query, status
+from sqlalchemy import and_, select
+
+from airflow.api_fastapi.common.db.common import SessionDep
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.execution_api.datamodels.asset_event import (
+    AssetEventCollectionResponse,
+)
+from airflow.models.asset import AssetAliasModel, AssetEvent, AssetModel
+
+# TODO: Add dependency on JWT token
+router = AirflowRouter(
+    responses={
+        status.HTTP_404_NOT_FOUND: {"description": "Asset not found"},
+        status.HTTP_401_UNAUTHORIZED: {"description": "Unauthorized"},
+    },
+)
+
+
+def _get_asset_events_through_sql_clauses(
+    *, join_clause, where_clause, session: SessionDep
+) -> AssetEventCollectionResponse:
+    asset_events = session.scalars(
+        
select(AssetEvent).join(join_clause).where(where_clause).order_by(AssetEvent.timestamp)
+    )
+    return AssetEventCollectionResponse.model_validate({"asset_events": 
asset_events or []})
+
+
[email protected]("/by-asset")
+def get_asset_event_by_asset_name_uri(
+    name: Annotated[str, Query(description="The name of the Asset")],
+    uri: Annotated[str, Query(description="The URI of the Asset")],
+    session: SessionDep,
+) -> AssetEventCollectionResponse:
+    if name and uri:
+        where_clause = and_(AssetModel.name == name, AssetModel.uri == uri)

Review Comment:
   Cool



##########
airflow/utils/context.py:
##########
@@ -170,106 +149,6 @@ def _get_asset_from_db(name: str | None = None, uri: str 
| None = None) -> Asset
         return asset.to_public()
 
 
-class LazyAssetEventSelectSequence(LazySelectSequence[AssetEvent]):
-    """
-    List-like interface to lazily access AssetEvent rows.
-
-    :meta private:
-    """
-
-    @staticmethod
-    def _rebuild_select(stmt: TextClause) -> Select:
-        return select(AssetEvent).from_statement(stmt)
-
-    @staticmethod
-    def _process_row(row: Row) -> AssetEvent:
-        return row[0]
-
-
[email protected](init=False)
-class InletEventsAccessors(Mapping[Union[int, Asset, AssetAlias, AssetRef], 
LazyAssetEventSelectSequence]):
-    """
-    Lazy mapping for inlet asset events accessors.
-
-    :meta private:
-    """
-
-    _inlets: list[Any]
-    _assets: dict[AssetUniqueKey, Asset]
-    _asset_aliases: dict[AssetAliasUniqueKey, AssetAlias]
-    _session: Session

Review Comment:
   Would this be a breaking change?



##########
task_sdk/tests/execution_time/test_context.py:
##########
@@ -354,3 +363,51 @@ def test__get_item__asset_ref(self, access_key, asset, 
mock_supervisor_comms):
         assert len(outlet_event_accessors) == 1
         assert outlet_event_accessor.key == internal_key
         assert outlet_event_accessor.extra == {}
+
+
+TEST_INLETS = [
+    Asset(name="test_uri", uri="test://test"),
+    AssetAlias(name="name"),
+    Asset.ref(name="test_uri"),
+    Asset.ref(uri="test://test/"),
+]
+
+
+class TestInletEventAccessor:
+    @pytest.fixture
+    def sample_inlet_evnets_accessor(self, mock_supervisor_comms):
+        mock_supervisor_comms.get_message.side_effect = [
+            AssetResult(name="test_uri", uri="test://test", group="asset"),
+            AssetResult(name="test_uri", uri="test://test", group="asset"),
+        ]
+        return InletEventsAccessors(inlets=TEST_INLETS)
+
+    @pytest.mark.usefixtures("mock_supervisor_comms")
+    def test__iter__(self, sample_inlet_evnets_accessor):
+        for actual, expected in zip(sample_inlet_evnets_accessor, TEST_INLETS):
+            assert actual == expected
+
+    @pytest.mark.usefixtures("mock_supervisor_comms")
+    def test__len__(self, sample_inlet_evnets_accessor):
+        # len(TEST_INLETS)

Review Comment:
   Lets remove this



##########
task_sdk/tests/execution_time/test_task_runner.py:
##########
@@ -67,6 +67,7 @@
 )

Review Comment:
   Can we also add a task trying to access inlet events in here? Example: 
`test_run_with_asset_outlets`



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