Skip to content

Commit 12f60c0

Browse files
committed
Handle trailing comments in DuckDB run SQL
1 parent e0218ef commit 12f60c0

5 files changed

Lines changed: 108 additions & 26 deletions

File tree

.agent/research/m3-duckdb-run-sql-models.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ dbt Core v1:
3535
`core/dbt/parser/unit_tests.py` references to `macro.dbt.is_incremental`:
3636
incremental models commonly include `is_incremental()` in parseable SQL even
3737
when this slice still rejects incremental materialization before execution.
38+
- `core/dbt/graph/selector.py::get_graph_queue`,
39+
`core/dbt/graph/queue.py::GraphQueue`, and
40+
`core/dbt/task/runnable.py::{get_graph_queue, run_queue}`: selected runnable
41+
nodes execute through a dependency-aware graph queue.
3842

3943
dbt Core v2 / Fusion:
4044

@@ -58,14 +62,21 @@ dbt Core v2 / Fusion:
5862
Fusion carries `is_incremental()` as a dbt macro. dxt parses the zero-argument
5963
call narrowly so run can report the unsupported incremental boundary before
6064
compile-time Jinja rendering.
65+
- `crates/dbt-dag/src/schedule.rs::Schedule` and
66+
`crates/dbt-dag/src/deps_mgmt.rs::topological_sort`: Fusion represents DAG
67+
scheduling and topological ordering explicitly.
6168

6269
## dxt Ownership
6370

6471
- `src/project/duckdb.zig`: DuckDB CLI-backed database path resolution,
6572
local-file path guardrails, table/view materialization SQL rendering, and
66-
execution.
73+
execution. Relative DuckDB profile paths resolve from the loaded
74+
`profiles.yml` directory as a deterministic dxt-local choice for this
75+
CLI-backed slice; the cited Fusion auth code grounds `path` as the DuckDB
76+
database option, not that relative-path base.
6777
- `src/project/run_results.zig`: minimal v6 `run_results.json` rendering for
68-
successful SQL model runs.
78+
successful SQL model runs. Failed and partial run-results artifacts are
79+
planned but not implemented in this first success-only execution slice.
6980
- `src/project/profile.zig`: narrow scalar DuckDB `path` capture.
7081
- `src/project.zig`: current command facade orchestration for `run`.
7182
- `tests/schemas/dbt_run_results_v6_m3_slice.schema.json`: pinned schema slice
@@ -75,22 +86,29 @@ dbt Core v2 / Fusion:
7586

7687
- Native Zig tests cover DuckDB materialization SQL rendering, conflicting
7788
table/view drop SQL, trailing SQL terminator trimming for wrapped model SQL,
78-
unsupported materialization rejection, DuckDB profile `path` capture,
79-
`is_incremental()` config scanning, and run-results JSON shape.
89+
preserving non-terminated SQL trailing comments, unsupported materialization
90+
rejection, DuckDB profile `path` capture, `is_incremental()` config scanning,
91+
and run-results JSON shape.
8092
- Pytest black-box coverage executes `dxt run` against copied and generated
8193
fixtures, verifies dependency-order execution where lexical order conflicts
8294
with graph order, checks table-to-view replacement on rerun, checks
83-
trailing-semicolon SQL model execution, checks profile-relative DuckDB paths,
84-
queries the resulting DuckDB database through the DuckDB CLI, validates
85-
`run_results.json` against the pinned schema slice, and keeps non-model, non-DuckDB,
86-
unsupported-materialization, and `build` boundaries explicit.
95+
trailing-semicolon SQL model execution including trailing SQL comments, checks
96+
profile-relative DuckDB paths, queries the resulting DuckDB database through
97+
the DuckDB CLI, validates `run_results.json` against the pinned schema slice,
98+
and keeps non-model, non-DuckDB, unsupported-materialization, and `build`
99+
boundaries explicit.
87100

88101
## Stop Conditions
89102

90103
- Do not implement `dxt build` execution in this slice.
91104
- Do not implement seeds, tests, snapshots, incremental, ephemeral, Python
92105
models, hooks, grants, docs persistence, catalog introspection, relation
93106
staging/backup rename semantics, adapter caching, or threaded scheduling.
107+
- Do not treat direct `create or replace` as full dbt materialization parity.
108+
It is a temporary shortcut for the M3 table/view success path; full parity
109+
needs intermediate/backup relation handling and cleanup semantics.
110+
- Do not emit failed or partial `run_results.json` in this success-only slice.
111+
Failure artifacts belong in the follow-up runner/task-result slice.
94112
- Do not call DuckDB from Python product code. Python remains a black-box test
95113
harness only.
96114
- Do not treat the external CLI backend as the long-term adapter ABI; replace it

PLAN.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,15 @@ materialization execution, catalog introspection, or run-results artifacts.
358358
Current DuckDB SQL model run source note:
359359
`.agent/research/m3-duckdb-run-sql-models.md` maps dbt Core v1 Run Results v6
360360
schema and run-result processing plus Fusion run-results structs, task stats,
361-
DuckDB profile `path`, and DuckDB table/view SQL primitives to dxt's first
362-
execution slice. This slice lets `dxt run` execute selected enabled DuckDB SQL
363-
models with `table` and `view` materializations through a Zig-owned external
364-
DuckDB CLI backend, write compiled SQL, `manifest.json`, and a minimal
365-
`run_results.json`, and reject non-model selections, non-DuckDB adapters, and
366-
unsupported materializations explicitly. It does not implement `build`
367-
execution, seeds, tests, snapshots, incremental, ephemeral, hooks, grants, docs
368-
persistence, catalog introspection, relation staging/backup rename parity,
361+
DuckDB profile `path`, DuckDB table/view SQL primitives, and dbt/Fusion DAG
362+
queue ordering to dxt's first execution slice. This slice lets `dxt run`
363+
execute selected enabled DuckDB SQL models with `table` and `view`
364+
materializations through a Zig-owned external DuckDB CLI backend, write compiled
365+
SQL, `manifest.json`, and a minimal success-only `run_results.json`, and reject
366+
non-model selections, non-DuckDB adapters, and unsupported materializations
367+
explicitly. It does not implement `build` execution, seeds, tests, snapshots,
368+
incremental, ephemeral, hooks, grants, docs persistence, catalog introspection,
369+
failed or partial run-results artifacts, relation staging/backup rename parity,
369370
threaded scheduling, or embedded `libduckdb`.
370371

371372
The next source-grounded M1/M2 slices after macro block variant support are:
@@ -731,7 +732,7 @@ Exit criteria:
731732
- `dxt ls` now lists dbt-selectable resources from the same parser graph, including scalar project/CLI var-resolved dependency edges, with stable text/JSON output and basic name/FQN wildcards, tag wildcards, slash-aware `path:` wildcards, exact `package:`/`package:this`, `source:` wildcards including package-qualified source selectors, `exposure:` wildcards, `resource_type:`, `test_type:generic`, config materialization, comma intersection, whitespace union, multi-argument selector lists, repeated selector flags, leading/trailing `+` graph expansion, and exact exclude filters; macros are emitted in artifacts but not exposed as `ls` resources.
732733
- `dxt compile` has started as a render-only M2 boundary for the current graph subset. It loads and resolves the same Zig parser graph, applies `--select` and `--exclude`, compiles selected enabled SQL model nodes, writes compiled SQL under `target/compiled/<package>/...`, and emits `compiled`, `compiled_code`, `compiled_path`, `relation_name`, `extra_ctes`, and `extra_ctes_injected` only for compiled model nodes. The current compiler renders `config` to empty text, literal or narrow scalar var-backed `ref`/`source` calls to deterministic quoted relation names, profile-derived `target.*`, current-model `this`, and quoted literal inline `config(schema=..., alias=...)` as default dbt relation schema/identifier components without opening a database connection.
733734
- `dxt docs generate` has started as an adapter-free docs artifact boundary. It loads and resolves the same Zig parser graph, applies `--select` and `--exclude` to compiled model output, writes compiled SQL, writes `manifest.json`, and writes an empty dbt-shaped `catalog.json` because adapter relation introspection is not implemented yet. Macro execution, materializations, tests, profiles-derived relation identity, adapters, `run_results.json`, non-empty `catalog.json`, and `docs serve` remain out of scope.
734-
- `dxt run` has started the M3 DuckDB execution path for selected enabled SQL models. It loads and resolves the same Zig parser graph, applies supported selectors/excludes, compiles selected SQL models, validates that selected models use only `table` or `view` materializations before opening DuckDB, executes selected models in dependency order through a Zig-owned external DuckDB CLI backend, writes compiled SQL, writes `manifest.json`, and writes a minimal dbt-shaped `run_results.json` v6 slice. It supports default `target/dxt.duckdb` output plus scalar DuckDB profile `path` resolved relative to the loaded `profiles.yml` directory. It does not execute seeds, tests, snapshots, incremental, ephemeral, hooks, grants, docs persistence, catalog introspection, relation staging/backup rename parity, threaded scheduling, `:memory:`, MotherDuck, or embedded `libduckdb`.
735+
- `dxt run` has started the M3 DuckDB execution path for selected enabled SQL models. It loads and resolves the same Zig parser graph, applies supported selectors/excludes, compiles selected SQL models, validates that selected models use only `table` or `view` materializations before opening DuckDB, executes selected models in dependency order through a Zig-owned external DuckDB CLI backend, writes compiled SQL, writes `manifest.json`, and writes a minimal dbt-shaped success-only `run_results.json` v6 slice after completed runs. It supports default `target/dxt.duckdb` output plus scalar DuckDB profile `path` resolved relative to the loaded `profiles.yml` directory as a deterministic dxt-local path-base choice for this first CLI-backed slice. It does not execute seeds, tests, snapshots, incremental, ephemeral, hooks, grants, docs persistence, catalog introspection, failure/partial run-results artifacts, relation staging/backup rename parity, threaded scheduling, `:memory:`, MotherDuck, or embedded `libduckdb`.
735736
- `dxt build` remains a truthful execution preflight boundary. It loads and resolves the same Zig parser graph, applies supported selectors/excludes, compiles selected SQL models where applicable, writes `manifest.json`, and then fails before seed/model/test execution with explicit runner boundary errors.
736737
- Synthetic fixtures cover one model, model refs, seed refs, source refs, narrow scalar var-backed model/source refs with CLI overrides and positional string defaults, exposure refs to models and sources, combined source/model YAML, inline config/tag selection, config materialization selection, comma-intersection selection, YAML model properties and columns, emitted `unique`, `not_null`, `accepted_values`, and `relationships` generic test nodes, project macro artifacts, macro block variants, macro materialization `supported_languages`, and macro properties including patched `docs` and `meta`, configured `macro-paths` replacing the default macro directory, installed package macros with package-qualified calls and package-local macro calls, installed package models, seeds, sources, docs, exposures, package YAML model properties, root package config overrides, and package-qualified/package-local refs/sources, macro calls recorded in model and macro `depends_on.macros`, docs blocks with literal `doc` descriptions, disabled models, disabled ref diagnostics, unmatched model-property warnings, duplicate model and docs diagnostics, unsupported dynamic doc diagnostics, unresolved var diagnostics for var-backed refs without scalar/default values, missing doc diagnostics, malformed docs block diagnostics, unresolved package macro diagnostics, and unsupported unknown macro-call diagnostics.
737738
- The committed M1 public Jaffle gate lives in `scripts/check_jaffle_shop_duckdb_parse.py`. It clones a pinned public Jaffle Shop DuckDB ref into a temporary directory by default, runs the Zig `dxt` binary, validates the current M1 manifest schema slice, asserts the supported partial manifest shape with five SQL models, three CSV seeds, two docs blocks, twenty supported generic test nodes, model/test `refs` artifact fields, dependency maps, materialization/docs config, and checks representative `dxt ls` selector behavior for resource types, materialization config, wildcards, path selectors, and graph expansion. It is a developer-side Python compatibility harness only; product parse/list behavior remains implemented in Zig. Remaining M1 work includes package-provided generic tests/macros beyond the current narrow macro call surface and deeper Jaffle artifact parity.

0 commit comments

Comments
 (0)