Skip to content

Commit 7f795b7

Browse files
authored
fix: sqlmesh materializations (#4809)
* fix: disable `dev` on restatements * chore: update env * chore: add sqlmesh dagster testing docs * fix: use updated options * chore: update dagster-sqlmesh dep
1 parent b758e82 commit 7f795b7

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ SQLMESH_DUCKDB_LOCAL_PATH=/tmp/oso.duckdb
1616
DAGSTER_USE_LOCAL_SECRETS=True
1717
#DAGSTER_GCP_SECRETS_PREFIX=dagster
1818

19+
# OSO's python libraries are configured to use json logging by default but this
20+
# can be annoying when viewing things locally. This will configure logs to be
21+
# output in a more human-readable format.
22+
OSO_ENABLE_JSON_LOGS=0
23+
1924
## Google Cloud setup
2025
# You will need to generate Google application credentials.
2126
# You can log in via `gcloud auth application-default login`

apps/docs/docs/contribute-data/setup/index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,40 @@ Notice that after `-m` the code location's module path is specified. It is
215215
useful to note for newcomers that the `warehouse/` path in the repository is not
216216
considered a python module as it does not contain a `__init__.py` file and does
217217
not appear as a python module in the root `pyproject.toml`
218+
219+
### Running dagster with sqlmesh locally
220+
221+
This is mostly for the OSO team as most people should not need to run sqlmesh on
222+
the dagster UI in a local fashion. It should be enough for anyone looking to add
223+
models to run sqlmesh on it's own. The only reason to run sqlmesh locally is to
224+
ensure that the dagster-sqlmesh integration is working as expected with our
225+
particular pipeline.
226+
227+
Some environment variables need to be set in your `.env`:
228+
229+
```bash
230+
# While not strictly necessary, you likely want the sqlmesh dagster asset
231+
# caching enabled so restarting doesn't take so long.
232+
DAGSTER_ASSET_CACHE_ENABLED=1
233+
DAGSTER_ASSET_CACHE_DIR=/path/to/some/cache/dir # change this
234+
# You can set this number to anything reasonable for your testing use case
235+
DAGSTER_ASSET_CACHE_DEFAULT_TTL_SECONDS=3600
236+
# `local` uses duckdb
237+
# `local-trino` uses a locally deployed trino
238+
# Suggestion is to use `local` as it's faster. This doc assumes duckdb.
239+
DAGSTER_SQLMESH_GATEWAY=local
240+
SQLMESH_TESTING_ENABLED=1
241+
OSO_ENABLE_JSON_LOGS=0
242+
```
243+
244+
Then you should run the sqlmesh local test setup to get your local sqlmesh
245+
duckdb initialized with oso local seed data.
246+
247+
```bash
248+
uv run oso local sqlmesh-test --duckdb
249+
```
250+
251+
Now it should be possible run sqlmesh and dagster locally. When materializing
252+
sqlmesh assets, it might complain about some out of date dependencies. Since we
253+
ran the local test setup, the data it's depending on should have been added by
254+
the oso local seed setup.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ dependencies = [
6767
"kr8s==0.20.9",
6868
"structlog>=25.4.0",
6969
"pandas-gbq>=0.29.2",
70-
"dagster-sqlmesh>=0.19.0",
70+
"dagster-sqlmesh>=0.20.0",
7171
"oso-core",
7272
"pyoso",
7373
"metrics-service"

uv.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

warehouse/oso_dagster/assets/sqlmesh/sqlmesh.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ def run_sqlmesh(
194194
config.allow_destructive_models
195195
)
196196

197-
# If we specify a dev_environment, we will first plan it for safety
198-
if dev_environment:
197+
# If we specify a dev_environment, we will first plan it for
198+
# safety. Restatements are ignored as they may end up duplicating
199+
# work based on how restatement in planning works.
200+
if dev_environment and not config.restate_models:
199201
context.log.info("Planning dev environment")
200202
all(
201203
sqlmesh.run(
@@ -206,6 +208,7 @@ def run_sqlmesh(
206208
end=config.end,
207209
restate_models=restate_models,
208210
skip_run=True,
211+
materializations_enabled=False,
209212
)
210213
)
211214

0 commit comments

Comments
 (0)