Skip to content

Commit 03680a1

Browse files
authored
Merge branch 'current' into mirnawong1-patch-26
2 parents e233c53 + bb8bc58 commit 03680a1

File tree

1 file changed

+154
-3
lines changed

1 file changed

+154
-3
lines changed

website/docs/reference/resource-properties/description.md

Lines changed: 154 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ description: "This guide explains how to use the description key to add YAML des
1414
{ label: 'Analyses', value: 'analyses', },
1515
{ label: 'Macros', value: 'macros', },
1616
{ label: 'Data tests', value: 'data_tests', },
17+
{ label: 'Unit tests', value: 'unit_tests', },
1718
]
1819
}>
1920
<TabItem value="models">
@@ -150,24 +151,81 @@ macros:
150151

151152
<VersionBlock firstVersion="1.9">
152153

154+
You can add a description to a [singular data test](/docs/build/data-tests#singular-data-tests) or a [generic data test](/docs/build/data-tests#generic-data-tests).
155+
153156
<File name='tests/schema.yml'>
154157

155158
```yml
159+
# Singular data test example
160+
156161
version: 2
157162

158163
data_tests:
159164
- name: data_test_name
160165
description: markdown_string
161-
162166
```
167+
</File>
168+
169+
<File name='tests/schema.yml'>
170+
171+
```yml
172+
# Generic data test example
173+
174+
version: 2
163175

176+
models:
177+
- name: model_name
178+
columns:
179+
- name: column_name
180+
tests:
181+
- unique:
182+
description: markdown_string
183+
```
164184
</File>
165185
166186
</VersionBlock>
167187
168188
<VersionBlock lastVersion="1.8">
169189
170-
The `description` property is available for generic and singular data tests beginning in dbt v1.9.
190+
The `description` property is available for [singular data tests](/docs/build/data-tests#singular-data-tests) or [generic data tests](/docs/build/data-tests#generic-data-tests) beginning in dbt v1.9.
191+
192+
</VersionBlock>
193+
194+
</TabItem>
195+
196+
<TabItem value="unit_tests">
197+
198+
<VersionBlock firstVersion="1.8">
199+
200+
<File name='models/schema.yml'>
201+
202+
```yml
203+
unit_tests:
204+
- name: unit_test_name
205+
description: "markdown_string"
206+
model: model_name
207+
given: ts
208+
- input: ref_or_source_call
209+
rows:
210+
- {column_name: column_value}
211+
- {column_name: column_value}
212+
- {column_name: column_value}
213+
- {column_name: column_value}
214+
- input: ref_or_source_call
215+
format: csv
216+
rows: dictionary | string
217+
expect:
218+
format: dict | csv | sql
219+
fixture: fixture_name
220+
```
221+
222+
</File>
223+
224+
</VersionBlock>
225+
226+
<VersionBlock lastVersion="1.7">
227+
228+
The `description` property is available for [unit tests](/docs/build/unit-tests) beginning in dbt v1.8.
171229

172230
</VersionBlock>
173231

@@ -176,13 +234,17 @@ The `description` property is available for generic and singular data tests begi
176234
</Tabs>
177235

178236
## Definition
179-
A user-defined description. Can be used to document:
237+
238+
A user-defined description used to document:
239+
180240
- a model, and model columns
181241
- sources, source tables, and source columns
182242
- seeds, and seed columns
183243
- snapshots, and snapshot columns
184244
- analyses, and analysis columns
185245
- macros, and macro arguments
246+
- data tests, and data test columns
247+
- unit tests for models
186248

187249
These descriptions are used in the documentation website rendered by dbt (refer to [the documentation guide](/docs/build/documentation) or [dbt Explorer](/docs/collaborate/explore-projects)).
188250

@@ -196,6 +258,18 @@ Be mindful of YAML semantics when providing a description. If your description c
196258

197259
## Examples
198260

261+
This section contains examples of how to add descriptions to various resources:
262+
263+
- [Add a simple description to a model and column](#add-a-simple-description-to-a-model-and-column) <br />
264+
- [Add a multiline description to a model](#add-a-multiline-description-to-a-model) <br />
265+
- [Use some markdown in a description](#use-some-markdown-in-a-description) <br />
266+
- [Use a docs block in a description](#use-a-docs-block-in-a-description) <br />
267+
- [Link to another model in a description](#link-to-another-model-in-a-description)
268+
- [Include an image from your repo in your descriptions](#include-an-image-from-your-repo-in-your-descriptions) <br />
269+
- [Include an image from the web in your descriptions](#include-an-image-from-the-web-in-your-descriptions) <br />
270+
- [Add a description to a data test](#add-a-description-to-a-data-test) <br />
271+
- [Add a description to a unit test](#add-a-description-to-a-unit-test) <br />
272+
199273
### Add a simple description to a model and column
200274

201275
<File name='models/schema.yml'>
@@ -400,3 +474,80 @@ models:
400474

401475
If mixing images and text, also consider using a docs block.
402476

477+
### Add a description to a data test
478+
479+
<VersionBlock lastVersion="1.8">
480+
481+
<VersionCallout version="1.9" />
482+
483+
</VersionBlock>
484+
485+
You can add a `description` property to a generic or singular data test.
486+
487+
#### Generic data test
488+
489+
This example shows a generic data test that checks for unique values in a column for the `orders` model.
490+
491+
<File name='models/<filename>.yml'>
492+
493+
```yaml
494+
version: 2
495+
496+
models:
497+
- name: orders
498+
columns:
499+
- name: order_id
500+
tests:
501+
- unique:
502+
description: "The order_id is unique for every row in the orders model"
503+
```
504+
</File>
505+
506+
#### Singular data test
507+
508+
This example shows a singular data test that checks to ensure all values in the `payments` model are not negative (≥ 0).
509+
510+
<File name='tests/<filename>.yml'>
511+
512+
```yaml
513+
version: 2
514+
data_tests:
515+
- name: assert_total_payment_amount_is_positive
516+
description: >
517+
Refunds have a negative amount, so the total amount should always be >= 0.
518+
Therefore return records where total amount < 0 to make the test fail.
519+
520+
```
521+
</File>
522+
523+
Note that in order for the test to run, the `tests/assert_total_payment_amount_is_positive.sql` SQL file has to exist in the `tests` directory.
524+
525+
### Add a description to a unit test
526+
527+
<VersionBlock lastVersion="1.7">
528+
529+
<VersionCallout version="1.8" />
530+
531+
</VersionBlock>
532+
533+
This example shows a unit test that checks to ensure the `opened_at` timestamp is properly truncated to a date for the `stg_locations` model.
534+
535+
<File name='models/<filename>.yml'>
536+
537+
```yaml
538+
unit_tests:
539+
- name: test_does_location_opened_at_trunc_to_date
540+
description: "Check that opened_at timestamp is properly truncated to a date."
541+
model: stg_locations
542+
given:
543+
- input: source('ecom', 'raw_stores')
544+
rows:
545+
- {id: 1, name: "Rego Park", tax_rate: 0.2, opened_at: "2016-09-01T00:00:00"}
546+
- {id: 2, name: "Jamaica", tax_rate: 0.1, opened_at: "2079-10-27T23:59:59.9999"}
547+
expect:
548+
rows:
549+
- {location_id: 1, location_name: "Rego Park", tax_rate: 0.2, opened_date: "2016-09-01"}
550+
- {location_id: 2, location_name: "Jamaica", tax_rate: 0.1, opened_date: "2079-10-27"}
551+
```
552+
553+
</File>

0 commit comments

Comments
 (0)