Skip to content

Commit 1354c7b

Browse files
committed
fix: use custom translator properly in sample dagster
1 parent f177310 commit 1354c7b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sample/dagster_project/definitions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
AssetKey,
99
Definitions,
1010
MaterializeResult,
11+
ResourceParam,
1112
asset,
1213
define_asset_job,
1314
)
@@ -27,12 +28,18 @@
2728
SQLMESH_CACHE_PATH = os.path.join(SQLMESH_PROJECT_PATH, ".cache")
2829
DUCKDB_PATH = os.path.join(CURR_DIR, "../../db.db")
2930

30-
sqlmesh_config = SQLMeshContextConfig(
31+
class CustomSQLMeshContextConfig(SQLMeshContextConfig):
32+
custom_key: str
33+
34+
def get_translator(self):
35+
return RewrittenSQLMeshTranslator(self.custom_key)
36+
37+
sqlmesh_config = CustomSQLMeshContextConfig(
3138
path=SQLMESH_PROJECT_PATH,
3239
gateway="local",
40+
custom_key="custom_sqlmesh_prefix"
3341
)
3442

35-
3643
class RewrittenSQLMeshTranslator(SQLMeshDagsterTranslator):
3744
"""A contrived SQLMeshDagsterTranslator that flattens the catalog of the
3845
sqlmesh project and only uses the table db and name
@@ -85,7 +92,7 @@ def test_source() -> pl.DataFrame:
8592
)
8693

8794

88-
@asset(deps=[AssetKey(["sqlmesh", "full_model"])])
95+
@asset(deps=[AssetKey(["custom_sqlmesh_prefix", "full_model"])])
8996
def post_full_model() -> pl.DataFrame:
9097
"""An asset that depends on the `full_model` asset from the sqlmesh project.
9198
This is used to test that the sqlmesh assets are correctly materialized and
@@ -109,7 +116,7 @@ def post_full_model() -> pl.DataFrame:
109116
enabled_subsetting=True,
110117
)
111118
def sqlmesh_project(
112-
context: AssetExecutionContext, sqlmesh: SQLMeshResource, sqlmesh_config: SQLMeshContextConfig
119+
context: AssetExecutionContext, sqlmesh: SQLMeshResource, sqlmesh_config: ResourceParam[SQLMeshContextConfig]
113120
) -> t.Iterator[MaterializeResult[t.Any]]:
114121
yield from sqlmesh.run(context, config=sqlmesh_config)
115122

0 commit comments

Comments
 (0)