Skip to content

Commit

Permalink
[dagster-tableau] Use Tableau translator instance in spec loader and …
Browse files Browse the repository at this point in the history
…state-backed defs
  • Loading branch information
maximearmstrong committed Dec 27, 2024
1 parent 5fe42bb commit b666549
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_asset_spec(self, data: TableauContentData) -> dg.AssetSpec:


tableau_specs = load_tableau_asset_specs(
tableau_workspace, dagster_tableau_translator=MyCustomTableauTranslator
tableau_workspace,
dagster_tableau_translator=MyCustomTableauTranslator, # type: ignore
)
defs = dg.Definitions(assets=[*tableau_specs], resources={"tableau": tableau_workspace})
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,15 @@ def build_defs(
@experimental
def load_tableau_asset_specs(
workspace: BaseTableauWorkspace,
dagster_tableau_translator: Type[DagsterTableauTranslator] = DagsterTableauTranslator,
dagster_tableau_translator: Optional[DagsterTableauTranslator] = None,
) -> Sequence[AssetSpec]:
"""Returns a list of AssetSpecs representing the Tableau content in the workspace.
Args:
workspace (Union[TableauCloudWorkspace, TableauServerWorkspace]): The Tableau workspace to fetch assets from.
dagster_tableau_translator (Type[DagsterTableauTranslator]): The translator to use
to convert Tableau content into AssetSpecs. Defaults to DagsterTableauTranslator.
dagster_tableau_translator (Optional[DagsterTableauTranslator]): The translator to use
to convert Tableau content into :py:class:`dagster.AssetSpec`.
Defaults to :py:class:`DagsterTableauTranslator`.
Returns:
List[AssetSpec]: The set of assets representing the Tableau content in the workspace.
Expand All @@ -549,7 +550,7 @@ def load_tableau_asset_specs(
return check.is_list(
TableauWorkspaceDefsLoader(
workspace=initialized_workspace,
translator_cls=dagster_tableau_translator,
translator=dagster_tableau_translator or DagsterTableauTranslator(),
)
.build_defs()
.assets,
Expand Down Expand Up @@ -598,7 +599,7 @@ def build_client(self) -> None:
@record
class TableauWorkspaceDefsLoader(StateBackedDefinitionsLoader[Mapping[str, Any]]):
workspace: BaseTableauWorkspace
translator_cls: Type[DagsterTableauTranslator]
translator: Type[DagsterTableauTranslator]

@property
def defs_key(self) -> str:
Expand All @@ -608,16 +609,14 @@ def fetch_state(self) -> TableauWorkspaceData:
return self.workspace.fetch_tableau_workspace_data()

def defs_from_state(self, state: TableauWorkspaceData) -> Definitions:
translator = self.translator_cls()

all_external_data = [
*state.data_sources_by_id.values(),
*state.sheets_by_id.values(),
*state.dashboards_by_id.values(),
]

all_external_asset_specs = [
translator.get_asset_spec(
self.translator.get_asset_spec(
TableauTranslatorData(content_data=content, workspace_data=state)
)
for content in all_external_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_translator_custom_metadata(
resource.build_client()

all_asset_specs = load_tableau_asset_specs(
workspace=resource, dagster_tableau_translator=MyCustomTranslator
workspace=resource, dagster_tableau_translator=MyCustomTranslator()
)
asset_spec = next(spec for spec in all_asset_specs)

Expand Down

0 comments on commit b666549

Please sign in to comment.