Skip to content

Commit c150019

Browse files
authored
Merge branch 'main' into feat/test-use-project-index
2 parents 79972f3 + 1f96a72 commit c150019

50 files changed

Lines changed: 2750 additions & 123 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/dependabot.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,28 @@ updates:
3232
directory: '/'
3333
schedule:
3434
interval: 'weekly'
35+
- package-ecosystem: 'pip'
36+
directory: '/docs'
37+
schedule:
38+
interval: 'weekly'
39+
groups:
40+
# The docs toolchain (MkDocs, its theme and plugins, pdoc, Pygments) is
41+
# built and verified as a whole, so bump it in a single PR.
42+
docs:
43+
patterns:
44+
- '*'
45+
ignore:
46+
# MkDocs 2.0 removes the plugin and theme systems that Material for
47+
# MkDocs and our plugins depend on, so a major bump can't be taken as-is.
48+
- dependency-name: 'mkdocs'
49+
update-types: ['version-update:semver-major']
50+
# mkdocs-material 9.8+ requires Python >= 3.11, but Read the Docs builds
51+
# with Python 3.10 (.readthedocs.yaml). Drop this once that is raised.
52+
- dependency-name: 'mkdocs-material'
53+
versions: ['>=9.8']
54+
# pdoc renders the API reference through a custom template
55+
# (pdoc/templates/), and the docs-build CI job doesn't run it, so a major
56+
# bump would land untested. Upgrade pdoc majors by hand with
57+
# `make api-docs`.
58+
- dependency-name: 'pdoc'
59+
update-types: ['version-update:semver-major']

‎.github/workflows/pr.yaml‎

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
vscode: ${{ steps.filter.outputs.vscode }}
2222
lsp: ${{ steps.filter.outputs.lsp }}
2323
ci: ${{ steps.filter.outputs.ci }}
24+
docs: ${{ steps.filter.outputs.docs }}
2425
steps:
2526
- uses: actions/checkout@v7
2627
- uses: dorny/paths-filter@v4
@@ -46,6 +47,10 @@ jobs:
4647
- '.github/**'
4748
- 'Makefile'
4849
- '.pre-commit-config.yaml'
50+
docs:
51+
- 'docs/**'
52+
- 'mkdocs.yml'
53+
- '.readthedocs.yaml'
4954
5055
doc-tests:
5156
needs: changes
@@ -73,6 +78,33 @@ jobs:
7378
source .venv/bin/activate
7479
make doc-test
7580
81+
docs-build:
82+
needs: changes
83+
if:
84+
needs.changes.outputs.docs == 'true' || needs.changes.outputs.ci ==
85+
'true' || github.ref == 'refs/heads/main'
86+
runs-on: ubuntu-latest
87+
env:
88+
UV: '1'
89+
steps:
90+
- uses: actions/checkout@v7
91+
- name: Set up Python
92+
# Match the Python version Read the Docs builds with (.readthedocs.yaml)
93+
uses: actions/setup-python@v7
94+
with:
95+
python-version: '3.10'
96+
- name: Install uv
97+
uses: astral-sh/setup-uv@v7
98+
- name: Install dependencies
99+
run: |
100+
uv venv .venv
101+
source .venv/bin/activate
102+
make install-doc
103+
- name: Build docs
104+
run: |
105+
source .venv/bin/activate
106+
mkdocs build --strict
107+
76108
style-and-cicd-tests:
77109
needs: changes
78110
if:
@@ -403,9 +435,43 @@ jobs:
403435
./.github/scripts/manage-test-db.sh "${{ matrix.engine }}"
404436
"$TEST_DB_NAME" up
405437
- name: Run tests
438+
env:
439+
# Temporary BigQuery diagnostics: since 2026-10-31 the BigQuery runner either shuts
440+
# down or stops responding mid-pytest, and its log is never uploaded. Keep the
441+
# evidence in files, stop pytest before the job limit so the runner can recover,
442+
# and upload the files in the steps below. Remove once fixed.
443+
PYTHONUNBUFFERED: ${{ matrix.engine == 'bigquery' && '1' || '' }}
444+
PYTEST_ADDOPTS: ${{ matrix.engine == 'bigquery' && '-v' || '' }}
406445
run: |
407446
source .venv/bin/activate
408-
make ${{ matrix.engine }}-test
447+
if [ "${{ matrix.engine }}" != "bigquery" ]; then
448+
make ${{ matrix.engine }}-test
449+
exit
450+
fi
451+
mkdir -p test-results
452+
(
453+
while true; do
454+
echo "[resources $(date -u +%T)] $(free -m | awk '/Mem:/{print "mem_used="$3"MB mem_avail="$7"MB"}') $(free -m | awk '/Swap:/{print "swap_used="$3"MB"}') $(df -h / | awk 'NR==2{print "disk_used="$5}')"
455+
ps -eo rss=,args= --sort=-rss | head -4 | awk '{rss=$1; $1=""; printf " rss=%dMB %.120s\n", rss/1024, $0}'
456+
sleep 5
457+
done
458+
) >> test-results/bigquery-resources.log 2>&1 &
459+
trap "kill $! 2>/dev/null || true" EXIT
460+
make engine-bigquery-install
461+
uv pip install -e ".[bigframes]"
462+
# Same commands as the Makefile's bigquery-test target, under a timeout so
463+
# pytest itself (not just make) is stopped before the 25 minute job limit.
464+
set -o pipefail
465+
timeout --kill-after=60s 18m pytest -n auto -m "bigquery" --reruns 3 \
466+
--junitxml=test-results/junit-bigquery.xml 2>&1 | tee test-results/bigquery-pytest.log
467+
- name: Collect BigQuery diagnostics
468+
if: ${{ always() && matrix.engine == 'bigquery' }}
469+
run: |
470+
mkdir -p test-results
471+
sudo dmesg -T | grep -iE 'out of memory|oom|killed process' > test-results/bigquery-dmesg.log || true
472+
echo "== kernel OOM messages"; cat test-results/bigquery-dmesg.log
473+
echo "== last resource samples"; tail -n 60 test-results/bigquery-resources.log || true
474+
echo "== last pytest output"; tail -n 60 test-results/bigquery-pytest.log || true
409475
- name: Tear down test database
410476
if: always()
411477
run:
@@ -470,13 +536,26 @@ jobs:
470536
- name: Install code-server
471537
# Pinned so that a code-server release cannot change the editor UI the
472538
# tests drive without the change showing up here first.
473-
run: curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.137.0
539+
# The installer curls the .deb once. A reset (curl exit 56) fails the
540+
# job. A repeat resumes the partial file the installer leaves behind.
541+
run: |
542+
set -euo pipefail
543+
for attempt in 1 2 3 4 5; do
544+
if curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.137.0; then
545+
exit 0
546+
fi
547+
echo "code-server install failed (attempt ${attempt}); retrying"
548+
sleep $((attempt * 5))
549+
done
550+
echo "code-server install failed after 5 attempts"
551+
exit 1
474552
- name: Install Playwright browsers
475553
working-directory: ./vscode/extension
476554
run: pnpm exec playwright install
477555
- name: Run e2e tests
478556
working-directory: ./vscode/extension
479-
timeout-minutes: 30
557+
# CI runs one worker. That needs a longer cap than the old 30 minutes.
558+
timeout-minutes: 60
480559
run: |
481560
source ../../.venv/bin/activate
482561
pnpm run test:e2e

‎docs/concepts/audits.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,44 @@ SQLMesh comes with a suite of built-in generic audits that cover a broad set of
195195

196196
This section describes the audits, grouped by general purpose.
197197

198+
### Filter rows with condition
199+
200+
All built-in audits accept an optional `condition` argument to select the rows to audit. Set it on an audit invocation in the model's `audits` property. Omitting it is equivalent to `condition := TRUE`, which keeps the audit's existing row scope.
201+
202+
Write the condition as a SQL boolean expression in the model's dialect. Use column identifiers and SQL literals normally, without quoting the entire expression as a string. For example, this model checks `customer_id` for `NULL` only in rows where `region = 'us'`:
203+
204+
```sql linenums="1"
205+
MODEL (
206+
name demo.orders,
207+
kind FULL,
208+
dialect duckdb,
209+
audits (
210+
not_null(
211+
columns := (customer_id),
212+
condition := (region = 'us')
213+
)
214+
)
215+
);
216+
217+
SELECT 1 AS customer_id, 'us' AS region;
218+
```
219+
220+
For compound predicates, use parentheses to preserve `AND` / `OR` precedence, such as `condition := (region = 'us' AND (customer_id > 0 OR customer_id IS NULL))`. As with SQL `WHERE`, only rows for which the condition evaluates to `TRUE` are included. If a predicate such as `region = 'us'` evaluates to `NULL`, that row is excluded; use `IS NULL` or explicit null handling when those rows should be included.
221+
222+
Do not use the literal `condition := NULL` to select no rows. Some built-in audits, including `not_null`, combine the condition with other checks using the `@AND` macro, which removes literal `NULL` arguments when rendering SQL. In those audits, a literal `NULL` does not restrict the audited rows. Use `condition := FALSE` to select no rows.
223+
224+
Aggregate and window-based audits perform their checks over the selected rows. For example, `unique_values` checks duplicates within that population. The following invocation requires at least one row with `region = 'us'`:
225+
226+
```sql
227+
number_of_rows(threshold := 0, condition := (region = 'us'))
228+
```
229+
230+
If no rows match, the result depends on the audit. The filtered `not_null` check above passes, while this `number_of_rows` check fails.
231+
232+
Each invocation has its own condition and arguments. A condition affects only that audit; it does not filter model materialization, other audits, or downstream models. For incremental by time range models, it further restricts the interval SQLMesh is auditing, without adding historical intervals.
233+
234+
The `_non_blocking` variants accept the same argument. The condition selects rows, while blocking controls what happens if the audit fails. For a user-defined audit, a parameter named `condition` only filters rows if its query uses the parameter, such as `WHERE @condition`.
235+
198236
### Generic assertion audit
199237

200238
The `forall` audit is the most generic built-in audit, allowing arbitrary boolean SQL expressions.
@@ -251,6 +289,8 @@ MODEL (
251289
#### at_least_one, at_least_one_non_blocking
252290
Ensures that specified columns contain at least one non-NULL value.
253291

292+
The audit fails when no row has a non-NULL value, including when the table is empty. For `INCREMENTAL_BY_TIME_RANGE` models the audit only sees the interval being processed, so an empty interval also fails. Use `at_least_one_non_blocking` if empty tables or intervals should log a warning instead of stopping the run.
293+
254294
This example asserts that the `zip` column contains at least one non-NULL value:
255295

256296
```sql linenums="1"

‎docs/concepts/macros/sqlmesh_macros.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ would be rendered as:
887887

888888
```sql linenums="1"
889889
SELECT
890-
CASE WHEN a IS NULL AND b IS NULL AND c IS NULL THEN NULL ELSE COALESCE(a, 0) + COALESCE(b, 0) + COALESCE(c, 0) END
890+
CASE WHEN a IS NULL AND b IS NULL AND c IS NULL THEN NULL ELSE (COALESCE(a, 0) + COALESCE(b, 0) + COALESCE(c, 0)) END
891891
FROM foo
892892
```
893893

@@ -906,7 +906,7 @@ would be rendered as:
906906

907907
```sql linenums="1"
908908
SELECT
909-
CASE WHEN a IS NULL AND b IS NULL AND c IS NULL THEN NULL ELSE COALESCE(a, 0) - COALESCE(b, 0) - COALESCE(c, 0) END
909+
CASE WHEN a IS NULL AND b IS NULL AND c IS NULL THEN NULL ELSE (COALESCE(a, 0) - COALESCE(b, 0) - COALESCE(c, 0)) END
910910
FROM foo
911911
```
912912

@@ -925,7 +925,7 @@ would be rendered as:
925925

926926
```sql linenums="1"
927927
SELECT
928-
a / NULLIF(b, 0)
928+
(a / NULLIF(b, 0))
929929
FROM foo
930930
```
931931

‎docs/requirements.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
mkdocs==1.4.2
2-
mkdocs-include-markdown-plugin==6.0.6
3-
mkdocs-material==9.0.5
4-
mkdocs-material-extensions==1.1.1
5-
mkdocs-glightbox==0.3.7
1+
mkdocs==1.6.1
2+
mkdocs-include-markdown-plugin==7.3.0
3+
mkdocs-material==9.7.7
4+
mkdocs-material-extensions==1.3.1
5+
mkdocs-glightbox==0.5.3
66
pdoc==14.5.1
7-
pygments==2.19.2 # Temporary pin: 2.20.0 breaks docs build; revisit after the fix
7+
pygments==2.21.0

‎mkdocs.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,16 @@ theme:
149149
palette:
150150
- media: "(prefers-color-scheme: light)"
151151
scheme: default
152-
primary: #3C64E2
153-
accent: #3C64E2
152+
primary: custom
153+
accent: custom
154154
toggle:
155155
icon: material/weather-sunny
156156
name: Switch to dark mode
157157
# Palette toggle for dark mode
158158
- media: "(prefers-color-scheme: dark)"
159159
scheme: slate
160-
primary: #3C64E2
161-
accent: #3C64E2
160+
primary: custom
161+
accent: custom
162162
toggle:
163163
icon: material/weather-night
164164
name: Switch to light mode

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ slack = ["slack_sdk"]
133133
snowflake = [
134134
"cryptography",
135135
"snowflake-connector-python[pandas,secure-local-storage]",
136-
"snowflake-snowpark-python",
136+
"snowflake-snowpark-python>=1.0.0",
137137
]
138138
starrocks = ["pymysql"]
139139
trino = ["trino"]

‎sqlmesh/cli/main.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@
4646
OPTIONAL_LOCAL_COMMANDS = ("lint", "test")
4747

4848

49+
def _is_restate_arg(arg: str) -> bool:
50+
"""Whether ``arg`` is a ``--restate-model`` / ``-r`` option token.
51+
52+
Covers the four spellings Click accepts: ``--restate-model VALUE``,
53+
``--restate-model=VALUE``, ``-r VALUE`` and ``-rVALUE``.
54+
"""
55+
if arg == "--restate-model" or arg.startswith("--restate-model="):
56+
return True
57+
if arg == "-r" or (arg.startswith("-r") and not arg.startswith("--")):
58+
return True
59+
return False
60+
61+
4962
class _SQLMeshGroup(click.Group):
5063
def parse_args(self, ctx: click.Context, args: t.List[str]) -> t.List[str]:
5164
rest = super().parse_args(ctx, args)
@@ -154,6 +167,14 @@ def cli(
154167
if ctx.invoked_subcommand == "test" and "--use-project-index" in ctx.meta["subcommand_args"]:
155168
load = False
156169

170+
# `plan --restate-model` operates entirely against state, so a project with no
171+
# local model definitions should still be allowed to run (parity with `run`).
172+
# Local loading itself stays on so that backfill expansion, unit tests, and the
173+
# linter continue to work when model files are present.
174+
restating = ctx.invoked_subcommand == "plan" and any(
175+
_is_restate_arg(arg) for arg in ctx.meta["subcommand_args"]
176+
)
177+
157178
configs = load_configs(config, Context.CONFIG_TYPE, paths, dotenv_path=dotenv)
158179
log_limit = list(configs.values())[0].log_limit
159180

@@ -172,7 +193,7 @@ def cli(
172193
logger.exception("Failed to initialize SQLMesh context")
173194
raise
174195

175-
if load and not context.models:
196+
if load and not context.models and not restating:
176197
raise click.ClickException(
177198
f"`{paths}` doesn't seem to have any models... cd into the proper directory or specify the path(s) with -p."
178199
)

‎sqlmesh/core/audit/builtin.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ def create_non_blocking_copy(audit: Audit) -> Audit:
137137
)
138138

139139
# at_least_one(column=column_name)
140+
# The aggregate is computed over the whole table rather than per group: grouping by the constant
141+
# produces no groups at all when the table is empty or @condition filters out every row, which
142+
# would make the audit pass even though no row has a non-NULL value.
140143
at_least_one_audit = ModelAudit(
141144
name="at_least_one",
142145
defaults={"condition": exp.true()},
143146
query="""
144-
SELECT 1
147+
SELECT COUNT(@column) AS cnt_not_null
145148
FROM @this_model
146149
WHERE @condition
147-
GROUP BY 1
148150
HAVING COUNT(@column) = 0
149151
""",
150152
)

‎sqlmesh/core/config/connection.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
24242424
# https://clickhouse.com/docs/en/operations/settings/settings
24252425
# - below are set to align with dbt-clickhouse
24262426
# - https://github.com/ClickHouse/dbt-clickhouse/blob/44d26308ea6a3c8ead25c280164aa88191f05f47/dbt/adapters/clickhouse/dbclient.py#L77
2427-
settings = self.connection_settings or {}
2427+
settings = dict(self.connection_settings or {})
24282428
# mutations_sync = 2: "The query waits for all mutations [ALTER statements] to complete on all replicas (if they exist)"
24292429
settings["mutations_sync"] = "2"
24302430
# insert_distributed_sync = 1: "INSERT operation succeeds only after all the data is saved on all shards"
@@ -2438,7 +2438,8 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
24382438
# - "INSERT succeeds only when ClickHouse manages to correctly write data to the insert_quorum of replicas during
24392439
# the insert_quorum_timeout"
24402440
# - "use majority number (number_of_replicas / 2 + 1) as quorum number"
2441-
settings["insert_quorum"] = "auto"
2441+
# - a value set by the user in connection_settings takes precedence
2442+
settings.setdefault("insert_quorum", "auto")
24422443

24432444
return {
24442445
"compress": compress,

0 commit comments

Comments
 (0)