Skip to content

Commit

Permalink
Add docs a for exposure generic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Sep 11, 2023
1 parent 7e1c61a commit 83deb76
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
100 changes: 100 additions & 0 deletions docs/guides/add-exposure-tests.mdx
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.
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
},
"guides/add-elementary-tests",
"guides/add-schema-tests",
"guides/add-exposure-tests",
"guides/python-tests"
]
},
Expand Down

0 comments on commit 83deb76

Please sign in to comment.