What I have learned this afternoon is that if you want to build a custom test on your sources, you can use the ‘model’ input to reference the source. I think this is confusing, in my opinion. It took me quite a while to discover this.
In other words, here is my .sql for my custom test:
{% test financialfieldstst(model, column_name) %}
select *
from {{ model }}
where try_to_number(coalesce({{ column_name }}, '0')) is null
{% endtest %}
And then in my sources.yml, I can reference this test:
sources:
- name: <source_name>
description: <description>
database: <db>
schema: <schema>
tables:
- name: <tablename>
description: <tabledesc>
columns:
- name: expenses_paid
description: total expenses paid
data_tests:
- financialfieldstst
Why don’t dbt incorporate a ‘source’ input to lessen the confusion between a source and a model? So my test would look like this:
{% test financialfieldstst(source, column_name) %}
select *
from {{ source }}
where try_to_number(coalesce({{ column_name }}, '0')) is null
{% endtest %}