-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dagster-sigma] Implement materializing workbooks (#25433)
## Summary Introduces asset definitions builder to allow materializing Sigma workbooks. Runs each scheduled materialization for the provided workbook. ## How I Tested These Changes Unit test, tested against Sigma instance.
- Loading branch information
Showing
8 changed files
with
296 additions
and
7 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
python_modules/libraries/dagster-sigma/dagster_sigma/__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
38 changes: 38 additions & 0 deletions
38
python_modules/libraries/dagster-sigma/dagster_sigma/assets.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,38 @@ | ||
from typing import cast | ||
|
||
from dagster import AssetExecutionContext, AssetsDefinition, AssetSpec, multi_asset | ||
from dagster._annotations import experimental | ||
|
||
|
||
@experimental | ||
def build_materialize_workbook_assets_definition( | ||
resource_key: str, | ||
spec: AssetSpec, | ||
) -> AssetsDefinition: | ||
"""Returns an AssetsDefinition which will, when materialized, | ||
run all materialization schedules for the targeted Sigma workbook. | ||
Note that this will not update portions of a workbook which are not | ||
assigned to a materialization schedule. | ||
For more information, see | ||
https://help.sigmacomputing.com/docs/materialization#create-materializations-in-workbooks | ||
Args: | ||
resource_key (str): The resource key to use for the Sigma resource. | ||
spec (AssetSpec): The asset spec of the Sigma workbook. | ||
Returns: | ||
AssetsDefinition: The AssetsDefinition which rebuilds a Sigma workbook. | ||
""" | ||
from dagster_sigma import SigmaOrganization | ||
|
||
@multi_asset( | ||
name=f"sigma_materialize_{spec.key.to_python_identifier()}", | ||
specs=[spec], | ||
required_resource_keys={resource_key}, | ||
) | ||
def asset_fn(context: AssetExecutionContext): | ||
sigma = cast(SigmaOrganization, getattr(context.resources, resource_key)) | ||
yield from sigma.run_materializations_for_workbook(spec) | ||
|
||
return asset_fn |
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
38 changes: 38 additions & 0 deletions
38
python_modules/libraries/dagster-sigma/dagster_sigma_tests/materialize_workbook.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,38 @@ | ||
from dagster import EnvVar, asset, define_asset_job | ||
from dagster._core.definitions.definitions_class import Definitions | ||
from dagster._utils.env import environ | ||
from dagster_sigma import ( | ||
SigmaBaseUrl, | ||
SigmaOrganization, | ||
build_materialize_workbook_assets_definition, | ||
load_sigma_asset_specs, | ||
) | ||
|
||
fake_client_id = "fake_client_id" | ||
fake_client_secret = "fake_client_secret" | ||
|
||
with environ({"SIGMA_CLIENT_ID": fake_client_id, "SIGMA_CLIENT_SECRET": fake_client_secret}): | ||
fake_token = "fake_token" | ||
resource = SigmaOrganization( | ||
base_url=SigmaBaseUrl.AWS_US, | ||
client_id=EnvVar("SIGMA_CLIENT_ID"), | ||
client_secret=EnvVar("SIGMA_CLIENT_SECRET"), | ||
) | ||
|
||
@asset | ||
def my_materializable_asset(): | ||
pass | ||
|
||
sigma_specs = load_sigma_asset_specs(resource) | ||
sigma_assets = [ | ||
build_materialize_workbook_assets_definition("sigma", spec) | ||
if spec.metadata.get("dagster_sigma/materialization_schedules") | ||
else spec | ||
for spec in sigma_specs | ||
] | ||
|
||
defs = Definitions( | ||
assets=[my_materializable_asset, *sigma_assets], | ||
jobs=[define_asset_job("all_asset_job")], | ||
resources={"sigma": resource}, | ||
) |
Oops, something went wrong.