Skip to content

Commit

Permalink
[dagster-tableau] Update custom translator example in Tableau docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Nov 20, 2024
1 parent 1afa7bc commit fed411e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
21 changes: 18 additions & 3 deletions docs/content/integrations/tableau.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defs = dg.Definitions(assets=[*tableau_specs], resources={"tableau": tableau_wor

### Customize asset definition metadata for Tableau assets

By default, Dagster will generate asset keys for each Tableau asset based on its type and name and populate default metadata. You can further customize asset properties by passing a custom <PyObject module="dagster_tableau" object="DagsterTableauTranslator" /> subclass to the <PyObject module="dagster_tableau" method="load_tableau_asset_specs" /> function. This subclass can implement methods to customize the asset keys or specs for each Tableau asset type.
By default, Dagster will generate asset spec for each Tableau asset based on its type and populate default metadata. You can further customize asset properties by passing a custom <PyObject module="dagster_tableau" object="DagsterTableauTranslator" /> subclass to the <PyObject module="dagster_tableau" method="load_tableau_asset_specs" /> function. This subclass can implement methods to customize the asset specs for each Tableau asset type.

```python file=/integrations/tableau/customize-tableau-asset-defs.py
from dagster_tableau import (
Expand All @@ -115,6 +115,7 @@ from dagster_tableau import (
from dagster_tableau.translator import TableauContentData

import dagster as dg
from dagster._core.definitions.asset_spec import replace_attributes

tableau_workspace = TableauCloudWorkspace(
connected_app_client_id=dg.EnvVar("TABLEAU_CONNECTED_APP_CLIENT_ID"),
Expand All @@ -130,8 +131,20 @@ tableau_workspace = TableauCloudWorkspace(
# Tableau assets, such as the owners or asset key
class MyCustomTableauTranslator(DagsterTableauTranslator):
def get_sheet_spec(self, data: TableauContentData) -> dg.AssetSpec:
# We add a custom team owner tag to all sheets
return super().get_sheet_spec(data)._replace(owners=["team:my_team"])
# We create the default asset spec for a given sheet using super()
default_spec = super().get_sheet_spec(data)
# We customize the team owner tag only for sheets
return replace_attributes(default_spec, owners=["team:my_team"])

def get_asset_spec(self, data: TableauContentData) -> dg.AssetSpec:
# We create the default asset spec using super()
default_spec = super().get_asset_spec(data)
# We customize the metadata and asset key prefix for all assets, including sheets
return replace_attributes(
default_spec,
key=default_spec.key.with_prefix("prefix"),
metadata={**default_spec.metadata, "custom": "metadata"},
)


tableau_specs = load_tableau_asset_specs(
Expand All @@ -140,6 +153,8 @@ tableau_specs = load_tableau_asset_specs(
defs = dg.Definitions(assets=[*tableau_specs], resources={"tableau": tableau_workspace})
```

Note that `super()` is called in each of the overridden methods to generate the default asset spec. It is best practice to generate the default asset spec before customizing it.

### Load Tableau assets from multiple workspaces

Definitions from multiple Tableau workspaces can be combined by instantiating multiple Tableau resources and merging their specs. This lets you view all your Tableau assets in a single asset graph:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dagster_tableau.translator import TableauContentData

import dagster as dg
from dagster._core.definitions.asset_spec import replace_attributes

tableau_workspace = TableauCloudWorkspace(
connected_app_client_id=dg.EnvVar("TABLEAU_CONNECTED_APP_CLIENT_ID"),
Expand All @@ -21,8 +22,20 @@
# Tableau assets, such as the owners or asset key
class MyCustomTableauTranslator(DagsterTableauTranslator):
def get_sheet_spec(self, data: TableauContentData) -> dg.AssetSpec:
# We add a custom team owner tag to all sheets
return super().get_sheet_spec(data)._replace(owners=["team:my_team"])
# We create the default asset spec for a given sheet using super()
default_spec = super().get_sheet_spec(data)
# We customize the team owner tag only for sheets
return replace_attributes(default_spec, owners=["team:my_team"])

def get_asset_spec(self, data: TableauContentData) -> dg.AssetSpec:
# We create the default asset spec using super()
default_spec = super().get_asset_spec(data)
# We customize the metadata and asset key prefix for all assets, including sheets
return replace_attributes(
default_spec,
key=default_spec.key.with_prefix("prefix"),
metadata={**default_spec.metadata, "custom": "metadata"},
)


tableau_specs = load_tableau_asset_specs(
Expand Down

0 comments on commit fed411e

Please sign in to comment.