-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1/p][dagster-embedded-etl] add SlingEventIterator (#23387)
## Summary Adds `SlingEventIterator` class which we can use to chain subsequent computation on Sling syncs. Motivated by stacked PR #23388. ## Test Plan Existing unit tests, inspect in editor to make sure type hints are happy.
- Loading branch information
Showing
2 changed files
with
68 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...modules/libraries/dagster-embedded-elt/dagster_embedded_elt/sling/sling_event_iterator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from collections import abc | ||
from typing import TYPE_CHECKING, Any, Dict, Generic, Iterator | ||
|
||
from dagster import AssetMaterialization | ||
from typing_extensions import TypeVar | ||
|
||
if TYPE_CHECKING: | ||
from .resources import SlingResource | ||
|
||
|
||
SlingEventType = AssetMaterialization | ||
|
||
# We define SlingEventIterator as a generic type for the sake of type hinting. | ||
# This is so that users who inspect the type of the return value of `SlingResource.replicate()` | ||
# will be able to see the inner type of the iterator, rather than just `SlingEventIterator`. | ||
T = TypeVar("T", bound=SlingEventType) | ||
|
||
|
||
class SlingEventIterator(Generic[T], abc.Iterator): | ||
"""A wrapper around an iterator of Sling events which contains additional methods for | ||
post-processing the events, such as fetching column metadata. | ||
""" | ||
|
||
def __init__( | ||
self, events: Iterator[T], sling_cli: "SlingResource", replication_config: Dict[str, Any] | ||
) -> None: | ||
self._inner_iterator = events | ||
self._sling_cli = sling_cli | ||
self._replication_config = replication_config | ||
|
||
def __next__(self) -> T: | ||
return next(self._inner_iterator) | ||
|
||
def __iter__(self) -> "SlingEventIterator[T]": | ||
return self |