-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs a for exposure generic tests
- Loading branch information
erikzaadi
committed
Sep 11, 2023
1 parent
7e1c61a
commit 83deb76
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
title: "Add exposure validation tests" | ||
--- | ||
|
||
After you [install the dbt package](/quickstart#install-the-dbt-package), you can add Elementary exposure validation tests. | ||
|
||
## Exposure validation dbt tests | ||
|
||
Elementary dbt package includes **exposure validation tests, implemented as [dbt tests](https://docs.getdbt.com/docs/building-a-dbt-project/tests)**. | ||
These tests can detect missing columns and column data types for defined exposures. | ||
|
||
## Configure your elementary exposure validation tests | ||
|
||
<Tip> | ||
You can read up about exposures and how to add them at [the dbt docs site](https://docs.getdbt.com/docs/build/exposures) | ||
</Tip> | ||
|
||
Within your `models` directory, add a file called `exposures.yml` | ||
|
||
```yml | ||
|
||
exposures: | ||
|
||
- name: customers | ||
label: Customer Dashboard | ||
type: dashboard | ||
maturity: high | ||
url: https://your.bi.tool/dashboards/1 | ||
description: > | ||
Shows customer growth | ||
depends_on: | ||
- ref('customers') | ||
|
||
owner: | ||
name: Callum McData | ||
email: [email protected] | ||
meta: | ||
columns: | ||
- name: "customer_id" | ||
|
||
``` | ||
|
||
<Note> | ||
You can optionally also specify the column data type (`data_type`) | ||
</Note> | ||
|
||
```yml | ||
|
||
- name: returned_orders | ||
label: Returned Orders | ||
type: dashboard | ||
maturity: high | ||
url: https://your.bi.tool/dashboards/2 | ||
description: > | ||
Returned orders over time | ||
depends_on: | ||
- ref('returned_orders') | ||
|
||
owner: | ||
name: Callum McData | ||
email: [email protected] | ||
meta: | ||
columns: | ||
- name: "order_id" | ||
data_type: "numeric" | ||
``` | ||
Then in your module schema, add the elementary exposure tests: | ||
```yml | ||
... | ||
- name: returned_orders | ||
description: This table contains all of the returned orders | ||
config: | ||
tags: ["finance"] | ||
|
||
tests: | ||
- elementary.volume_anomalies: | ||
tags: ["table_anomalies"] | ||
timestamp_column: "order_date" | ||
- exposure_schema_validity: | ||
tags: [elementary] | ||
|
||
``` | ||
|
||
We recommend adding a tag to the tests so you could execute these in a dedicated run using the selection parameter `--select tag:elementary`. | ||
|
||
Upon running the tests, if any issues will arise, you'll see your tests fail and in the test result query you'll be able to see the reasons: | ||
|
||
|
||
```sql | ||
SELECT 'customers' as exposure, 'https://your.bi.tool/dashboards/1' as url, 'different data type for the column customer_id numeric vs numeric' as error | ||
UNION ALL SELECT 'customers' as exposure, 'https://your.bi.tool/dashboards/1' as url, 'order_id column missing in the model' as error | ||
``` | ||
|
||
## What does it mean when a test fails? | ||
|
||
When a test fail, it means that an exposure is potentially broken, open the your BI tool to validate, and if needed update the `exposures.yml` or your model's schema. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters