dabla commented on code in PR #62922:
URL: https://github.com/apache/airflow/pull/62922#discussion_r3628685172
##########
task-sdk/src/airflow/sdk/execution_time/lazy_sequence.py:
##########
@@ -166,6 +169,80 @@ def __getitem__(self, key: int | slice) -> T | Sequence[T]:
return XCom.deserialize_value(_XComWrapper(msg.root))
+class XComIterable(Sequence):
+ """An iterable that lazily fetches XCom values one by one instead of
loading all at once."""
+
+ def __init__(self, task_id: str, dag_id: str, run_id: str, length: int,
map_index: int | None = None):
+ self.task_id = task_id
+ self.dag_id = dag_id
+ self.run_id = run_id
+ self.length = length
+ self.map_index = map_index
+
+ def __iter__(self) -> Iterator:
+ return _XComIterator(self)
+
+ def __len__(self) -> int:
+ return self.length
+
+ @overload
+ def __getitem__(self, key: int) -> Any: ...
+
+ @overload
+ def __getitem__(self, key: slice) -> Sequence[Any]: ...
+
+ def __getitem__(self, key: int | slice) -> Any | Sequence[Any]:
+ """Allow direct indexing so this works like a sequence."""
+ if isinstance(key, slice):
+ start, stop, step = key.indices(len(self))
+ return [self[i] for i in range(start, stop, step)]
Review Comment:
@kaxil Wouldn't it be better to do this in a separate
[PR](https://github.com/apache/airflow/pull/70223), so we already have the XCom
FastAPI route ready so once merged, we can use it here to not overwhelm this PR?
--
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]