diff --git a/docs/content/integrations/tableau.mdx b/docs/content/integrations/tableau.mdx index 2e9b69b79e086..d628fbdcfcc72 100644 --- a/docs/content/integrations/tableau.mdx +++ b/docs/content/integrations/tableau.mdx @@ -191,6 +191,7 @@ from dagster_tableau import ( TableauCloudWorkspace, build_tableau_materializable_assets_definition, load_tableau_asset_specs, + parse_tableau_external_and_materializable_asset_specs, ) import dagster as dg @@ -209,17 +210,9 @@ tableau_specs = load_tableau_asset_specs( workspace=tableau_workspace, ) -external_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") == "data_source" -] - -materializable_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") in ["dashboard", "sheet"] -] +external_asset_specs, materializable_asset_specs = ( + parse_tableau_external_and_materializable_asset_specs(tableau_specs) +) # Use the asset definition builder to construct the definition for tableau materializable assets defs = dg.Definitions( @@ -246,6 +239,7 @@ from dagster_tableau import ( TableauCloudWorkspace, build_tableau_materializable_assets_definition, load_tableau_asset_specs, + parse_tableau_external_and_materializable_asset_specs, ) import dagster as dg @@ -288,17 +282,9 @@ tableau_specs = load_tableau_asset_specs( workspace=tableau_workspace, ) -external_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") == "data_source" -] - -materializable_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") in ["dashboard", "sheet"] -] +external_asset_specs, materializable_asset_specs = ( + parse_tableau_external_and_materializable_asset_specs(tableau_specs) +) # Pass the sensor, Tableau resource, upstream asset, Tableau assets specs and materializable assets definition at once defs = dg.Definitions( diff --git a/docs/sphinx/sections/api/apidocs/libraries/dagster-tableau.rst b/docs/sphinx/sections/api/apidocs/libraries/dagster-tableau.rst index ba400c7e3ab07..1702bea324e7d 100644 --- a/docs/sphinx/sections/api/apidocs/libraries/dagster-tableau.rst +++ b/docs/sphinx/sections/api/apidocs/libraries/dagster-tableau.rst @@ -27,4 +27,4 @@ Assets (Tableau API) .. autofunction:: build_tableau_materializable_assets_definition - +.. autofunction:: parse_tableau_external_and_materializable_asset_specs diff --git a/examples/docs_snippets/docs_snippets/integrations/tableau/add-tableau-data-quality-warning.py b/examples/docs_snippets/docs_snippets/integrations/tableau/add-tableau-data-quality-warning.py index 786a6879fbfb3..475fa3a0054e4 100644 --- a/examples/docs_snippets/docs_snippets/integrations/tableau/add-tableau-data-quality-warning.py +++ b/examples/docs_snippets/docs_snippets/integrations/tableau/add-tableau-data-quality-warning.py @@ -2,6 +2,7 @@ TableauCloudWorkspace, build_tableau_materializable_assets_definition, load_tableau_asset_specs, + parse_tableau_external_and_materializable_asset_specs, ) import dagster as dg @@ -44,17 +45,9 @@ def tableau_run_failure_sensor( workspace=tableau_workspace, ) -external_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") == "data_source" -] - -materializable_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") in ["dashboard", "sheet"] -] +external_asset_specs, materializable_asset_specs = ( + parse_tableau_external_and_materializable_asset_specs(tableau_specs) +) # Pass the sensor, Tableau resource, upstream asset, Tableau assets specs and materializable assets definition at once defs = dg.Definitions( diff --git a/examples/docs_snippets/docs_snippets/integrations/tableau/refresh-and-materialize-tableau-assets.py b/examples/docs_snippets/docs_snippets/integrations/tableau/refresh-and-materialize-tableau-assets.py index b545e0f53de4e..65673e2ca6a15 100644 --- a/examples/docs_snippets/docs_snippets/integrations/tableau/refresh-and-materialize-tableau-assets.py +++ b/examples/docs_snippets/docs_snippets/integrations/tableau/refresh-and-materialize-tableau-assets.py @@ -2,6 +2,7 @@ TableauCloudWorkspace, build_tableau_materializable_assets_definition, load_tableau_asset_specs, + parse_tableau_external_and_materializable_asset_specs, ) import dagster as dg @@ -20,17 +21,9 @@ workspace=tableau_workspace, ) -external_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") == "data_source" -] - -materializable_asset_specs = [ - spec - for spec in tableau_specs - if spec.tags.get("dagster-tableau/asset_type") in ["dashboard", "sheet"] -] +external_asset_specs, materializable_asset_specs = ( + parse_tableau_external_and_materializable_asset_specs(tableau_specs) +) # Use the asset definition builder to construct the definition for tableau materializable assets defs = dg.Definitions( diff --git a/python_modules/libraries/dagster-tableau/dagster_tableau/asset_utils.py b/python_modules/libraries/dagster-tableau/dagster_tableau/asset_utils.py index 63e19561923ce..8e9648e97497d 100644 --- a/python_modules/libraries/dagster-tableau/dagster_tableau/asset_utils.py +++ b/python_modules/libraries/dagster-tableau/dagster_tableau/asset_utils.py @@ -8,6 +8,12 @@ def parse_tableau_external_and_materializable_asset_specs( specs: Sequence[AssetSpec], ) -> Tuple[Sequence[AssetSpec], Sequence[AssetSpec]]: + """Parses a list of Tableau AssetSpecs provided as input and return two lists of AssetSpecs, + one for the Tableau external assets and another one for the Tableau materializable assets. + + In Tableau, data sources are considered external assets, + while sheets and dashboards are considered materializable assets. + """ external_asset_specs = [ spec for spec in specs if TableauTagSet.extract(spec.tags).asset_type == "data_source" ]