-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dagster-fivetran] Scaffold DagsterFivetranTranslator for rework
- Loading branch information
1 parent
8c291f8
commit 7c954b2
Showing
3 changed files
with
84 additions
and
45 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
python_modules/libraries/dagster-fivetran/dagster_fivetran/v2/__init__.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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from dagster_fivetran.v2.resources import FivetranWorkspace as FivetranWorkspace | ||
from dagster_fivetran.v2.translator import DagsterFivetranTranslator as DagsterFivetranTranslator |
47 changes: 2 additions & 45 deletions
47
python_modules/libraries/dagster-fivetran/dagster_fivetran/v2/resources.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
81 changes: 81 additions & 0 deletions
81
python_modules/libraries/dagster-fivetran/dagster_fivetran/v2/translator.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,81 @@ | ||
from enum import Enum | ||
from typing import Any, Mapping, Sequence | ||
|
||
from dagster import _check as check | ||
from dagster._core.definitions.asset_key import AssetKey | ||
from dagster._core.definitions.asset_spec import AssetSpec | ||
from dagster._record import record | ||
|
||
|
||
class FivetranContentType(Enum): | ||
"""Enum representing each object in Fivetran's ontology.""" | ||
|
||
CONNECTOR = "connector" | ||
DESTINATION = "destination" | ||
|
||
|
||
@record | ||
class FivetranContentData: | ||
"""A record representing a piece of content in a Fivetran workspace. | ||
Includes the object's type and data as returned from the API. | ||
""" | ||
|
||
content_type: FivetranContentType | ||
properties: Mapping[str, Any] | ||
|
||
def to_cached_data(self) -> Mapping[str, Any]: | ||
return {"content_type": self.content_type.value, "properties": self.properties} | ||
|
||
@classmethod | ||
def from_cached_data(cls, data: Mapping[Any, Any]) -> "FivetranContentData": | ||
return cls( | ||
content_type=FivetranContentType(data["content_type"]), | ||
properties=data["properties"], | ||
) | ||
|
||
|
||
@record | ||
class FivetranWorkspaceData: | ||
"""A record representing all content in a Fivetran workspace. | ||
Provided as context for the translator so that it can resolve dependencies between content. | ||
""" | ||
|
||
connectors_by_id: Mapping[str, FivetranContentData] | ||
destinations_by_id: Mapping[str, FivetranContentData] | ||
|
||
@classmethod | ||
def from_content_data( | ||
cls, content_data: Sequence[FivetranContentData] | ||
) -> "FivetranWorkspaceData": | ||
raise NotImplementedError() | ||
|
||
|
||
class DagsterFivetranTranslator: | ||
"""Translator class which converts raw response data from the Fivetran API into AssetSpecs. | ||
Subclass this class to implement custom logic for each type of Fivetran content. | ||
""" | ||
|
||
def __init__(self, context: FivetranWorkspaceData): | ||
self._context = context | ||
|
||
@property | ||
def workspace_data(self) -> FivetranWorkspaceData: | ||
return self._context | ||
|
||
def get_asset_key(self, data: FivetranContentData) -> AssetKey: | ||
if data.content_type == FivetranContentType.CONNECTOR: | ||
return self.get_connector_asset_key(data) | ||
else: | ||
check.assert_never(data.content_type) | ||
|
||
def get_asset_spec(self, data: FivetranContentData) -> AssetSpec: | ||
if data.content_type == FivetranContentType.CONNECTOR: | ||
return self.get_connector_spec(data) | ||
else: | ||
check.assert_never(data.content_type) | ||
|
||
def get_connector_asset_key(self, data: FivetranContentData) -> AssetKey: | ||
raise NotImplementedError() | ||
|
||
def get_connector_spec(self, data: FivetranContentData) -> AssetSpec: | ||
raise NotImplementedError() |