Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dagster-sigma] Use get_asset_spec().key in DagsterSigmaTranslator #26035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def organization_data(self) -> SigmaOrganizationData:

def get_asset_key(self, data: Union[SigmaDataset, SigmaWorkbook]) -> AssetKey:
"""Get the AssetKey for a Sigma object, such as a workbook or dataset."""
return AssetKey(_coerce_input_to_valid_name(data.properties["name"]))
return self.get_asset_spec(data).key

def get_asset_spec(self, data: Union[SigmaDataset, SigmaWorkbook]) -> AssetSpec:
"""Get the AssetSpec for a Sigma object, such as a workbook or dataset."""
Expand All @@ -119,7 +119,7 @@ def get_asset_spec(self, data: Union[SigmaDataset, SigmaWorkbook]) -> AssetSpec:
]

return AssetSpec(
key=self.get_asset_key(data),
key=AssetKey(_coerce_input_to_valid_name(data.properties["name"])),
metadata=metadata,
kinds={"sigma", "workbook"},
deps={
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_asset_spec(self, data: Union[SigmaDataset, SigmaWorkbook]) -> AssetSpec:
}

return AssetSpec(
key=self.get_asset_key(data),
key=AssetKey(_coerce_input_to_valid_name(data.properties["name"])),
metadata=metadata,
kinds={"sigma", "dataset"},
deps={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dagster import EnvVar, define_asset_job
from dagster._core.definitions.asset_key import AssetKey
from dagster._core.definitions.asset_spec import AssetSpec
from dagster._core.definitions.definitions_class import Definitions
from dagster._utils.env import environ
from dagster_sigma import (
Expand All @@ -16,8 +16,11 @@
fake_token = "fake_token"

class MyCoolTranslator(DagsterSigmaTranslator):
def get_asset_key(self, data) -> AssetKey:
return super().get_asset_key(data).with_prefix("my_prefix")
def get_asset_spec(self, data) -> AssetSpec:
spec = super().get_asset_spec(data)
return spec.replace_attributes(
key=spec.key.with_prefix("my_prefix"),
)

resource = SigmaOrganization(
base_url=SigmaBaseUrl.AWS_US,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

from dagster._core.definitions.asset_key import AssetKey
from dagster._core.definitions.asset_spec import AssetSpec
from dagster._core.definitions.metadata.table import TableColumn, TableSchema
Expand Down Expand Up @@ -88,13 +90,12 @@ def test_dataset_translation() -> None:

def test_dataset_translation_custom_translator() -> None:
class MyCustomTranslator(DagsterSigmaTranslator):
def get_asset_key(self, data: SigmaDataset) -> AssetKey:
return super().get_asset_key(data).with_prefix("sigma")

def get_asset_spec(self, data: SigmaDataset) -> AssetSpec:
def get_asset_spec(self, data: Union[SigmaDataset, SigmaWorkbook]) -> AssetSpec:
spec = super().get_asset_spec(data)
if isinstance(data, SigmaDataset):
return spec._replace(description="Custom description")
spec = spec.replace_attributes(
key=spec.key.with_prefix("sigma"), description="Custom description"
)
return spec

sample_dataset = SigmaDataset(
Expand Down