Exercise 2
To create singular test to validate format check
on Year
column in aggregate_global_temperatures
model
Follow the instructions below using DBT:
Open your dbt project and navigate to the tests folder.
Create a new file called
assert_year_format_aggregate_global_temperatures.sql
or any suitable name for the singular test file.In the file, define the query to check whether the
year
column is in YYYY format inaggregate_global_emissions
view.Specify the view name in the query by referencing the
aggregate_global_temperatures
view. You can use theref()
function to refer to the view. For example,FROM {{ ref('aggregate_global_temperatures') }}
.Define the query in such a way that it should result output if any row has format other than YYYY format in
year
column.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.