-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema test blocks #1173
Comments
I wanted to share some of our latest thinking on schema test blocks, which we're hoping to include in v0.20.0. Necessary caveats: We're still working through the details and various implications; this is just the tip of the iceberg; anything below is still subject to change. SemanticsFirst off, I'd like to ditch the names "schema" and "data" tests, and many of the current distinctions between them. The two should provide the dbt developer two angles into the same functionality:
This issue is about the latter. Proposed syntax# macros/reusable_tests.sql
{% test not_null(model, column_name), adapter = 'default' %}
select * from {{ model }}
where {{ column_name }} is null
{% endtest %} # macros/schema.yml
tests:
- name: not_null
adapter: default
description: "Assert that {{ column_name }} is not null in {{ model }}"
fail_msg: "Found {{ result }} null values of {{ model }}.{{ column_name }}, which is {{ warn_or_error }}"
fail_calc: "count(*)" # this is default
args:
- name: model
description: "The model to test"
- name: column_name
description: "The column or expression to test" The YAML properties are optional—just the SQL definition is sufficient to define this test on models/columns/etc—but they're really what make the test block shine, and what takes it a step beyond the standard macro. In this world, packages of custom tests offer more than just a reusable bit of SQL: they offer a complete, packaged asset with richer behavior in docs/artifacts (a la #2959). Most custom schema tests existing today could upgrade easily by:
Tactical questions
|
Love this idea. Couple of initial thoughts, more to come...:
|
A As for a one-off test ( |
I've thought about this more: No! I think many of these properties would be shared between both types of tests. I totally see a one-off test ( Of course, some properties— I think both test types could also define The fact that both test types would have the majority of their resource properties in common feels like a strong argument in favor of centralizing them under a single
Having said all of the above, I think this is definitely still true. |
Describe the feature
dbt should support blocks that represent schema test definitions. A rough sketch of what these could look like:
Implementation ideas:
name
of the test block should dictate how the calling schema.yml file calls this testconfig
block should help provide a rendered name and description for the resulting test nodeImportant considerations:
count(*)
style tests to aselect *
style test could be really expensive. Let's keep that in mind as we build out this functionalityConfiguration ideas:
To support dynamic test node names and descriptions, the
config
block should accept two configs:A quick and imperfect example:
I know, I know, curlies inside of curlies. Let's figure out a sensible way to make these names and descriptions easy to write.
When this feature is live, we should deprecate the old-style schema test macros and mark them for removal in a future release.
Additional context
config
levelThe text was updated successfully, but these errors were encountered: