Declaring resource properties
Overview
While configurations tell dbt how to build something in your warehouse (for example, whether a model should be a table or view, or which SQL to use when running a snapshot), resource properties are used to declare things about your dbt project or data warehouse.
For example, you can use resource properties to:
- Describe models, snapshots, seed files, and their columns
- Assert "truths" about a model, in the form of tests, e.g. "this
id
column is unique" - Apply tags to resources
- Define existing tables contains raw data as sources
- Assert the expected "freshness" of this raw data
In dbt, these properties are declared in .yml
files, in the same directory as your resources. There's a few quirks for backwards compatibility reasons:
Resource | Default directories | Defined by |
---|---|---|
models | models/ | source-paths |
sources | models/ | source-paths |
seeds | data/ or models/ | data-paths or source-paths |
snapshots | snapshots/ or models/ | snapshot-paths or source-paths |
analyses | analyses/ or models/ | analysis-paths or source-paths |
macros | macros/ or models/ | macro-paths or source-paths |
You can name these files whatever_you_want.yml
and nest them arbitrarily deeply in subfolders within each directory.
info
schema.yml files
Previous versions of the docs referred to these as schema.yml
files — we've moved away from that terminology since the word schema
is used to mean other things when talking about databases, and people often thought that you had to name these files schema.yml
.
(Of course, you're still free to name your files schema.yml
)
Example
Here's an example that defines both sources
and models
for a project:
version: 2sources:- name: raw_jaffle_shopdescription: A replica of the postgres database used to power the jaffle_shop app.tables:- name: customerscolumns:- name: iddescription: Primary key of the tabletests:- unique- not_null- name: orderscolumns:- name: iddescription: Primary key of the tabletests:- unique- not_null- name: user_iddescription: Foreign key to customers- name: statustests:- accepted_values:values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']models:- name: stg_jaffle_shop__customerscolumns:- name: customer_idtests:- unique- not_null- name: stg_jaffle_shop__orderscolumns:- name: order_idtests:- unique- not_null- name: statustests:- accepted_values:values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']
Related documentation
You can find an exhaustive list of each property for a resource in the following docs:
- Model Properties
- Source Properties
- Seed Properties
- Snapshot Properties
- Analysis Properties
- Macro Properties
FAQs
Troubleshooting common errors
Invalid test config given in [model name]
This error occurs when your .yml
file does not conform to the structure expected by dbt. A full error message might look like:
* Invalid test config given in models/schema.yml near {'namee': 'event', ...}Invalid arguments passed to "UnparsedNodeUpdate" instance: 'name' is a required property, Additional properties are not allowed ('namee' was unexpected)
While verbose, an error like this should help you track down the issue. Here, the name
field was provided as namee
by accident. To fix this error, ensure that your .yml
conforms to the expected structure described in this guide.
Invalid syntax in your schema.yml file
If your .yml
file is not valid yaml, then dbt will show you an error like this:
Runtime ErrorSyntax error near line 6------------------------------5 | - name: events6 | description; "A table containing clickstream events from the marketing website"7 |Raw Error:------------------------------while scanning a simple keyin "<unicode string>", line 6, column 5:description; "A table containing clickstream events from the marketing website"^
This error occurred because a semicolon (;
) was accidentally used instead of a colon (:
) after the description
field. To resolve issues like this, find the .yml
file referenced in the error message and fix any syntax errors present in the file. There are online yaml validators that can be helpful here, but please be mindful of submitting sensitive information to third-party applications!