-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(looker): allow customization of
AssetKey
through `DagsterLooke…
…rTranslator` (#21835) ## Summary & Motivation Introduce a similar pattern to `DagsterDbtTranslator` to allow the user to customize asset keys. Next up, we'll allow the user to customize group name, tags, etc. ## How I Tested These Changes pytest
- Loading branch information
1 parent
19b2d3d
commit 4b07259
Showing
10 changed files
with
130 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
|
@@ -13,3 +13,5 @@ Assets | |
====== | ||
|
||
.. autodecorator:: looker_assets | ||
|
||
.. autoclass:: DagsterLookerTranslator |
1 change: 1 addition & 0 deletions
1
python_modules/libraries/dagster-looker/dagster_looker/__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,6 +1,7 @@ | ||
from dagster._core.libraries import DagsterLibraryRegistry | ||
|
||
from .asset_decorator import looker_assets as looker_assets | ||
from .dagster_looker_translator import DagsterLookerTranslator as DagsterLookerTranslator | ||
from .version import __version__ as __version__ | ||
|
||
DagsterLibraryRegistry.register("dagster-looker", __version__) |
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
51 changes: 51 additions & 0 deletions
51
python_modules/libraries/dagster-looker/dagster_looker/dagster_looker_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,51 @@ | ||
from pathlib import Path | ||
from typing import Any, Mapping, Tuple | ||
|
||
from dagster import AssetKey | ||
from dagster._annotations import experimental, public | ||
|
||
|
||
@experimental | ||
class DagsterLookerTranslator: | ||
"""Holds a set of methods that derive Dagster asset definition metadata given a representation | ||
of a LookML element (dashboards, explores, views). | ||
This class is exposed so that methods can be overriden to customize how Dagster asset metadata | ||
is derived. | ||
""" | ||
|
||
@public | ||
def get_asset_key(self, lookml_element: Tuple[Path, Mapping[str, Any]]) -> AssetKey: | ||
"""A method that takes in a dictionary representing a LookML element | ||
(dashboards, explores, views) and returns the Dagster asset key that represents the element. | ||
The LookML element is parsed using ``lkml``. You can learn more about this here: | ||
https://lkml.readthedocs.io/en/latest/simple.html. | ||
You can learn more about LookML dashboards and the properties available in this | ||
dictionary here: https://cloud.google.com/looker/docs/reference/param-lookml-dashboard. | ||
You can learn more about LookML explores and views and the properties available in this | ||
dictionary here: https://cloud.google.com/looker/docs/reference/lookml-quick-reference. | ||
This method can be overriden to provide a custom asset key for a LookML element. | ||
Args: | ||
lookml_element (Tuple[Path, Mapping[str, Any]]): A tuple with the path to file | ||
defining a LookML element, and a dictionary representing a LookML element. | ||
Returns: | ||
AssetKey: The Dagster asset key that represents the LookML element. | ||
""" | ||
lookml_element_path, lookml_element_props = lookml_element | ||
|
||
if lookml_element_path.suffixes == [".dashboard", ".lookml"]: | ||
return AssetKey(["dashboard", lookml_element_props["dashboard"]]) | ||
|
||
if lookml_element_path.suffixes == [".view", ".lkml"]: | ||
return AssetKey(["view", lookml_element_props["name"]]) | ||
|
||
if lookml_element_path.suffixes == [".model", ".lkml"]: | ||
return AssetKey(["explore", lookml_element_props["name"]]) | ||
|
||
raise ValueError(f"Unsupported LookML element: {lookml_element_path}") |
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