feat(engine): named test definitions — define a check once, apply by name across models#919
Merged
Conversation
…name across models
Adds reusable named data-quality tests (the declarative analogue of dbt's
generic tests). A `models/test_definitions.toml` defines `name -> { type + params
+ optional default column }`; a model applies one with a `[[use_test]]` block,
binding/overriding the column, severity, and filter at the use site:
# models/test_definitions.toml
[positive_amount]
type = "expression"
expression = "amount > 0"
# models/fct_orders.toml
[[use_test]]
name = "positive_amount"
column = "amount"
References resolve into ordinary `TestDecl`s at load and are appended to any
inline `[[tests]]`, so they execute identically through `rocky test` — no
change to the test-execution path. An unknown reference fails the load
(`ModelError::UnknownTest`), so a typo can't silently drop a check.
Loading rides a side-loader (`load_test_definitions_from_dir`). Resolution
generalizes the config-group threading from a `groups`-only param into a shared
`ModelLoadContext { groups, test_defs }`: the `*_with_groups` loaders become
`*_with_context`, and the bare `load_model_pair`/`parse_model_inline` pass an
empty context — zero `ModelConfig` churn, no output-schema change. Wired through
both the `.sql` loader (`load_models_from_dir`) and the `.rocky` salsa loader,
each with a regression test, and verified end-to-end through `rocky compile`
(valid references resolve; unknown ones error).
Documented in concepts/data-quality-checks.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Reusable named data-quality tests — the declarative analogue of dbt's generic tests (C3). Define an assertion once in
models/test_definitions.tomland apply it by name across many models/columns, instead of inlining the same[[tests]]block everywhere.Design
TestDecls at load and append to inline[[tests]], so they execute identically throughrocky test— no change to the test-execution path.[[use_test]]name fails the load (ModelError::UnknownTest), so a typo can't silently drop a check.load_test_definitions_from_dir). Resolution generalizes the config-group threading (from feat(engine): config groups — one definition fans out routing + strategy to N models #917) — thegroups-only param becomes a sharedModelLoadContext { groups, test_defs };*_with_groups→*_with_context; bareload_model_pair/parse_model_inlinepass an empty context. ZeroModelConfigchurn, no output-schema change (verified: no codegen/schema drift)..sql(load_models_from_dir) and.rocky(salsa) — each with a regression test, and verified end-to-end throughrocky compile(valid references resolve; unknown ones error).Tests
rocky-core: applied-by-reference (default column + severity), column-override + inline coexistence, unknown-name error.rocky-compiler:.rockymodel resolves a named test through the salsa loader. Full suites green (1357 core + 325 compiler).Documented in concepts/data-quality-checks.md.
cargo fmt + clippy
--all-targetsclean; no codegen/schema drift.