Skip to content

fix: support YAML-only snapshots (dbt v1.9+) - #83

Merged
eitsupi merged 6 commits into
mainfrom
fix/yaml-only-snapshots
Jun 6, 2026
Merged

fix: support YAML-only snapshots (dbt v1.9+)#83
eitsupi merged 6 commits into
mainfrom
fix/yaml-only-snapshots

Conversation

@eitsupi

@eitsupi eitsupi commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • dbt v1.9+ allows defining snapshots in YAML without a corresponding .sql file. These were previously silently ignored because SchemaFile had no snapshots field and the builder only read snapshot_sql_files.
  • Add SnapshotDefinition struct to yaml_schema.rs with name, description, and relation fields
  • Add process_yaml_snapshot_nodes() in the builder to register nodes for YAML-only snapshots and add upstream edges via the relation: ref('...') field

Behavior

  • YAML-only snapshots now appear in the graph as NodeType::Snapshot nodes
  • Edges are added from the upstream model when relation: ref('model_name') is present
  • If both a .sql file and a YAML definition exist for the same snapshot name, the SQL file takes precedence (YAML def is skipped, no duplicate node)
  • SQL-based snapshots are unaffected

Test plan

  • test_build_graph_yaml_only_snapshot — verifies node creation and upstream edge from relation
  • test_build_graph_yaml_snapshot_sql_takes_precedence — verifies no duplicate when SQL file exists
  • test_parse_yaml_only_snapshots — verifies YAML parsing of SnapshotDefinition
  • cargo test passes (83 tests)

🤖 Generated with Claude Code

eitsupi and others added 4 commits June 6, 2026 07:12
dbt v1.9+ allows defining snapshots in YAML without a corresponding
.sql file. These were previously silently dropped because SchemaFile
had no `snapshots` field and builder only read snapshot_sql_files.

- Add `SnapshotDefinition` struct to yaml_schema.rs with `name`,
  `description`, and `relation` fields
- Add `snapshots: Vec<SnapshotDefinition>` to `SchemaFile`
- Collect YAML snapshot definitions in `process_yaml_files()`
- Add `process_yaml_snapshot_nodes()` to register nodes for snapshots
  that have no matching SQL file, and add edges from the upstream model
  via the `relation: ref('...')` field (reuses `parse_exposure_ref()`)
- SQL-based snapshots are unaffected; YAML defs for them are skipped

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Collapse nested if-let in process_yaml_snapshot_nodes() to satisfy
  clippy::collapsible_if (-D warnings)
- Fix yaml snapshot tests: override stg_orders.sql with a source-free
  query so phantom source nodes don't inflate the expected node count

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
YAML-only snapshots using `relation: source('schema', 'table')` now
get a Source edge to the matching source node. If the source is not
defined in YAML, a phantom node is created (consistent with how SQL
snapshot source refs are handled by process_sql_edges).

- Add parse_relation_source() helper wrapping extract_sources()
- process_yaml_snapshot_nodes() checks source() before ref() and adds
  EdgeType::Source edges; falls through to ref() parsing otherwise
- Add tests for defined-source and phantom-source relation variants

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates dlin-core to support dbt v1.9+ “YAML-only” snapshots (snapshots defined in schema.yml without a corresponding .sql snapshot file) by parsing snapshot definitions from schema YAML and registering them as NodeType::Snapshot nodes in the lineage graph, including upstream edges derived from a relation: expression.

Changes:

  • Extend YAML schema parsing to include snapshots: entries via a new SnapshotDefinition type.
  • Add a builder pass that registers YAML-only snapshot nodes and derives upstream edges from relation: ref(...) / relation: source(...).
  • Add graph-builder tests covering YAML-only snapshots, SQL-precedence, and source(...) relations (including phantom-source behavior).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/dlin-core/src/parser/yaml_schema.rs Adds snapshots support to schema YAML parsing and tests parsing of YAML-only snapshot definitions.
crates/dlin-core/src/graph/builder/mod.rs Collects YAML snapshot defs during YAML processing and registers YAML-only snapshot nodes + relation-derived upstream edges during graph build.
crates/dlin-core/src/graph/builder/tests/build_graph.rs Adds end-to-end tests validating node creation, edge creation, and SQL-vs-YAML precedence for snapshots.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/dlin-core/src/graph/builder/mod.rs Outdated
Comment thread crates/dlin-core/src/graph/builder/mod.rs Outdated
eitsupi and others added 2 commits June 6, 2026 07:57
- For source() relations: use get_or_create_phantom_source() instead of
  inline phantom creation, so unresolved sources emit the standard
  warning and share the same canonical phantom node as SQL parsing
- For ref() relations: use get_or_create_phantom_ref() so unresolved
  refs create a phantom node with a warning instead of silently dropping
  the edge

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@eitsupi
eitsupi merged commit 6c8f41f into main Jun 6, 2026
12 checks passed
@eitsupi
eitsupi deleted the fix/yaml-only-snapshots branch June 6, 2026 08:19
@eitsupi eitsupi mentioned this pull request Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants