Skip to main content

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:

  1. Open your dbt project and navigate to the tests folder.

  2. Create a new file called assert_bkey_co2_emissions_and_temperatures_by_country.sql or any suitable name for the singular test file.

  3. In the file, define the query to check whether the COUNTRY_AVGTEMP_BKEY column is concatenation of COUNTRY ,YEAR ,and AVERAGETEMPERATURE with || delimiter in co2_emissions_and_temperatures_by_country table.

  4. Specify the table name in the query by referencing the co2_emissions_and_temperatures_by_country table. You can use the ref() function to refer to the table. For example, FROM {{ ref('co2_emissions_and_temperatures_by_country') }}.

  5. 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.

  6. Save the file.

  7. 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.