diff --git a/code_thingies/dbtlearn/macros/no_nulls_in_columns.sql b/code_thingies/dbtlearn/macros/no_nulls_in_columns.sql new file mode 100644 index 0000000..40af5d4 --- /dev/null +++ b/code_thingies/dbtlearn/macros/no_nulls_in_columns.sql @@ -0,0 +1,10 @@ +{% macro no_nulls_in_columns(model) %} + SELECT * + FROM + {{ model }} + WHERE + {% for col in adapter.get_columns_in_relation(model) -%} + {{col.column}} IS NULL OR + {% endfor %} + FALSE +{% endmacro %} \ No newline at end of file diff --git a/code_thingies/dbtlearn/tests/no_nulls_in_dim_listings.sql b/code_thingies/dbtlearn/tests/no_nulls_in_dim_listings.sql new file mode 100644 index 0000000..e2a6fb5 --- /dev/null +++ b/code_thingies/dbtlearn/tests/no_nulls_in_dim_listings.sql @@ -0,0 +1 @@ +{{ no_nulls_in_columns(ref('dim_listings_cleansed')) }} \ No newline at end of file diff --git a/notes/8.md b/notes/8.md index f96b728..bd7e45a 100644 --- a/notes/8.md +++ b/notes/8.md @@ -73,4 +73,11 @@ There are two kinds of tests: - Singular tests: you make any `SELECT` statement you want. If the `SELECT` statement is run and any data is found, the test is considered failed. If the statement is run and no rows are returned, the test is considered passed. - Built-in test: just a bunch of typical stuff: uniqueness, nullability, enum validations and relationship (referential integrity) -You can also define your own custom generic tests. \ No newline at end of file +You can also define your own custom generic tests. + + +## Macros + +- Macros are jinja templates. +- There are many built-in macros in dbt, but you can also use your own macros. +- dbt packages exist and you can use them to have more tests and macros that you can use. \ No newline at end of file