-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs a for exposure generic tests #1154
Merged
erikzaadi
merged 3 commits into
master
from
ele-1703-create-generic-test-for-exposure-stability
Sep 28, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,157 @@ | ||
--- | ||
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 changes in your models' columns that break downstream exposures, such as BI dashboards. | ||
|
||
## Configure your elementary exposure validation tests | ||
|
||
Within your `models` directory, add a file called `exposures.yml` | ||
|
||
```yml | ||
version: 2 | ||
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] | ||
``` | ||
|
||
<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> | ||
|
||
### Adding the Elementary exposure information | ||
|
||
For each exposure wish to be verified, you add a new property called `meta`: | ||
|
||
```yml | ||
version: 2 | ||
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: | ||
referenced_columns: | ||
- column_name: "customer_id" | ||
``` | ||
|
||
<Tip> | ||
In the Elementary Cloud, the exposures and exposure validation tests are added | ||
automatically, according to the actual dependency if your BI tool. | ||
</Tip> | ||
|
||
You can optionally also specify the column data type (`data_type`) | ||
|
||
```yml | ||
version: 2 | ||
- 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: | ||
referenced_columns: | ||
- column_name: "order_id" | ||
data_type: "numeric" | ||
``` | ||
|
||
In addition, if your exposure depends on several nodes, you can depend explicitly per column which source should be tested: | ||
|
||
```yml | ||
version: 2 | ||
- 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') | ||
- ref('orders') | ||
|
||
owner: | ||
name: Callum McData | ||
email: [email protected] | ||
meta: | ||
referenced_columns: | ||
- column_name: "order_id" | ||
data_type: "numeric" | ||
node: ref('returned_orders') | ||
- column_name: "customer_id" | ||
data_type: "numeric" | ||
node: ref('orders') | ||
|
||
``` | ||
|
||
### Adding the Elementary exposure tests for your module | ||
|
||
For each module schema you wish to verify the exposure dependencies, 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" | ||
- elementary.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 breaking changes are detected in the model, the test will 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 fails, it means that an exposure is potentially broken due to a missing or wrongly-typed column. Open the your BI tool to validate, and if you make any changes to your dashboards be sure to update the `exposures.yml` and your model schema accordingly. |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have this recommendation in all the test types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw it in https://github.com/elementary-data/elementary/blob/ele-1703-create-generic-test-for-exposure-stability/docs/guides/add-elementary-tests.mdx#L234