Exercise 6
To create singular test to validate business rule check
on COUNTRY_AVGTEMP_BKEY
column in co2_emissions_and_temperatures_by_country
model
Follow the instructions below using DBT:
Open your dbt project and navigate to the tests folder.
Create a new file called
assert_bkey_co2_emissions_and_temperatures_by_country.sql
or any suitable name for the singular test file.In the file, define the query to check whether the
COUNTRY_AVGTEMP_BKEY
column is concatenation ofCOUNTRY
,YEAR
,andAVERAGETEMPERATURE
with||
delimiter inco2_emissions_and_temperatures_by_country
table.Specify the table name in the query by referencing the
co2_emissions_and_temperatures_by_country
table. You can use theref()
function to refer to the table. For example,FROM {{ ref('co2_emissions_and_temperatures_by_country') }}
.Define the query in such a way that it should result output if any row has different value in
COUNTRY_AVGTEMP_BKEY
column other than concatenated value.Save the file.
Run the dbt test project to validate the result. You can use the
dbt test
command in your terminal to see if test case is successfully completed.