Enable sql_header
within generic data tests
#9854
Draft
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.
part of addressing #9775
This is part of proof-of-concept (POC). See dbt-labs/dbt-adapters#145 for the other piece.
Problem
Currently, any
sql_header
config doesn't have any effect for:And it only has effect for:
Put another way
The
sql_header
configuration only works for singular data tests that havestore_failures_as="table"
(orstore_failures=true
).Solution
Enable
sql_header
to apply to both singular and generic data tests regardless if they are storing failures or not.Cons
sql_header
will be applied twice when storing failures -- the 2nd time is essentially wasted because it isn't needed theresql_header
tocore/dbt/artifacts/resources/v1/config.py
andcore/dbt/parser/generic_test_builders.py
don't seem like quite the right place -- it seems like it would be better defined one level higher and then inheritedKicking the tires
Example project and commands to try this out
Project files:
models/model_with_singular_data_test.sql
models/model_with_generic_data_test.sql
tests/singular_data_test__store_failures_as_table.sql
tests/singular_data_test__store_failures_as_ephemeral.sql
models/_models.yml
Build the project (run the models and tests):
Open the logs file (
logs/dbt.log
).Then search for
-- CREATE TEMP FUNCTION
.All of the following should show up in the search (at the beginning of separate SQL statements) corresponding to each of the (4) main test cases:
Checklist