-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2/n][dagster-fivetran] Update DagsterFivetranTranslator and related classes for rework #25751
Merged
+104
−87
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ca6343
[dagster-fivetran] Scaffold DagsterFivetranTranslator for rework
maximearmstrong abc0107
Lint
maximearmstrong 3f2e8a4
Update translator post review
maximearmstrong f709655
Update folder structure
maximearmstrong bb5ddc0
Lint
maximearmstrong fed3154
Remove get_asset_key in DagsterFivetranTranslator
maximearmstrong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
93 changes: 93 additions & 0 deletions
93
python_modules/libraries/dagster-fivetran/dagster_fivetran/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,93 @@ | ||
from enum import Enum | ||
from typing import Any, Mapping, NamedTuple, Optional, Sequence | ||
|
||
from dagster._core.definitions.asset_key import AssetKey | ||
from dagster._core.definitions.asset_spec import AssetSpec | ||
from dagster._record import record | ||
from dagster._serdes.serdes import whitelist_for_serdes | ||
|
||
from dagster_fivetran.utils import metadata_for_table | ||
|
||
|
||
class FivetranConnectorTableProps(NamedTuple): | ||
table: str | ||
connector_id: str | ||
name: str | ||
connector_url: str | ||
schemas: Mapping[str, Any] | ||
database: Optional[str] | ||
service: Optional[str] | ||
|
||
|
||
class FivetranContentType(Enum): | ||
"""Enum representing each object in Fivetran's ontology.""" | ||
|
||
CONNECTOR = "connector" | ||
DESTINATION = "destination" | ||
|
||
|
||
@whitelist_for_serdes | ||
@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] | ||
|
||
|
||
@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() | ||
|
||
def to_fivetran_connector_table_props_data(self) -> Sequence[FivetranConnectorTableProps]: | ||
"""Method that converts a `FivetranWorkspaceData` object | ||
to a collection of `FivetranConnectorTableProps` objects. | ||
""" | ||
raise NotImplementedError() | ||
|
||
|
||
class DagsterFivetranTranslator: | ||
"""Translator class which converts a `FivetranConnectorTableProps` object into AssetSpecs. | ||
Subclass this class to implement custom logic for each type of Fivetran content. | ||
""" | ||
|
||
def get_asset_spec(self, props: FivetranConnectorTableProps) -> AssetSpec: | ||
"""Get the AssetSpec for a table synced by a Fivetran connector.""" | ||
schema_name, table_name = props.table.split(".") | ||
schema_entry = next( | ||
schema | ||
for schema in props.schemas["schemas"].values() | ||
if schema["name_in_destination"] == schema_name | ||
) | ||
table_entry = next( | ||
table_entry | ||
for table_entry in schema_entry["tables"].values() | ||
if table_entry["name_in_destination"] == table_name | ||
) | ||
|
||
metadata = metadata_for_table( | ||
table_entry, | ||
props.connector_url, | ||
database=props.database, | ||
schema=schema_name, | ||
table=table_name, | ||
) | ||
|
||
return AssetSpec( | ||
key=AssetKey(props.table.split(".")), | ||
metadata=metadata, | ||
kinds={"fivetran", *({props.service} if props.service else set())}, | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still want/need this class,
FivetranContentType
etc if it's not getting fed into the translator?In particular I think having the content type isn't necessary, since we aren't exposing this data to the user directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth keeping
FivetranContentType
for a few reasons:FivetranContentType
, it's easier to keep track of the type of theFivetranContentData
.fetch_fivetran_workspace_data
leverages theFivetranContentType
enum to create theFivetranWorkspaceData
.FivetranContentType
when creatingFivetranContentData
objects and theFivetranWorkspaceData
object, to differentiate connectors and destinations. See usage in subsequent PR, in [4/n][dagster-fivetran] Implementfetch_fivetran_workspace_data
#25788 and [5/n][dagster-fivetran] ImplementFivetranWorkspaceData
toFivetranConnectorTableProps
method #25797Overall, I'm in favor of keeping this to keep our design pattern for
XWorkspaceData
andfetch_x_workspace_data
as consistent as possible across integrations.