Skip to content

Commit 7bc9671

Browse files
Merge pull request #69 from dbt-labs/feat/add-sample-documentation
Documentation of sample dbt concepts in this project
2 parents 9e48f51 + c496288 commit 7bc9671

File tree

1 file changed

+281
-0
lines changed

1 file changed

+281
-0
lines changed

_samples/_samples_documentation.md

+281
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
# Documentation of sample dbt concepts in this project
2+
3+
## Sources
4+
**Source selection syntax [samples](sources/source_selection_syntax.md)**
5+
- Includes samples of how to test sources, source freshness, and building downstream from a source
6+
7+
**Source freshness [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__sources.yml)**
8+
- Includes freshness warnings, errors, and turning off source freshness on an individual source table
9+
10+
**Environment Variables to set source database [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__sources.yml)**
11+
- Use an environment variable to control which database you're using for a source
12+
13+
**Target to set schema [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__sources.yml)**
14+
- Use target to control which schema you're using for a source
15+
16+
**Quoting [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__sources.yml)**
17+
- Set quoting on the source database, schema, and identifier for a given source table
18+
19+
**Loader [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__sources.yml)**
20+
- Set the loader property on a source
21+
22+
## Models
23+
24+
**Model Configurations [samples](../models/_samples/staging/jaffle_shop/stg_jaffle_shop__customers.sql)**
25+
- Set the grants, post_hook, alias, materialized, persist_docs, schema, and database configurations on a model
26+
- The materialization strategy here overwrites the materialization set in the dbt_project.yml
27+
28+
**Set materialization in dbt_project.yml [samples](../dbt_project.yml)**
29+
- Sets all models in the marts folder to be configured as a table by default
30+
- Sets all models in the staging folder from the dbt_artifacts package to be materialized as ephemeral
31+
32+
## Tests
33+
34+
**Sample singular test on multiple models [samples](../tests/_samples/example_singular_test_multiple_models.sql)**
35+
- Create a singular test on multiple models
36+
37+
**Test configurations in a test [samples](../tests/_samples/audit_helper_compare_all_columns__stg_tpch__orders.sql)**
38+
- Sets test configurations, including setting severity to warning, on a test
39+
40+
**Test configurations in a yml file [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__models.yml)**
41+
- Configurations on a test including where, limit, severity, error if, warn if, and store failures
42+
43+
**Tests from packages [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__models.yml)**
44+
- Shows tests from dbt_utils package
45+
46+
**Helpful generic tests [samples](../tests/generic/)**
47+
- filtered_unique.sql: a test to allow you to run a unique test on a subset of records. Column level test with custom argument/
48+
- not_empty.sql: a simple test that makes sure that an object contains records. Model level test.
49+
- unique_and_not_null.sql: a test that checks that a column is both unique and not null in a single test. Column level test
50+
51+
**Test a seed [samples](../seeds/samples/_seeds.yml)**
52+
- Shows how to test a column on a seed
53+
54+
**Testing snapshots [samples](../snapshots/_samples/_example__snapshots.yml)**
55+
- Shows how to test snapshots
56+
57+
**Store all test failures only in prod target [samples](../dbt_project.yml)**
58+
- Sets the configurations in the dbt_project.yml file to store failures for tests only in prod
59+
60+
## Documentation
61+
**Multi-line description [samples](../models/_samples/staging/jaffle_shop/_jaffle_shop__models.yml)**
62+
- Shows multi-line description using `|` or `>`
63+
64+
**Create a doc block [samples](../models/staging/tpch/stg_tpch.md)**
65+
- Shows how to create a doc block
66+
67+
**Setting description using a doc blocks [samples](../models/staging/tpch/_tpch__models.yml)**
68+
- Shows how to call a doc block to set the description on an object
69+
70+
**Describe a seed [samples](../seeds/samples/_seeds.yml)**
71+
- Shows how to add descriptions on seeds
72+
73+
**Documenting snapshots [samples](../snapshots/_samples/_example__snapshots.yml)**
74+
- Shows how to document snapshots
75+
76+
## Seeds
77+
78+
**Create a seed [samples](../seeds/samples/alphabet_grouping.csv)**
79+
- Example of a seed
80+
81+
**Test and describe a seed [samples](../seeds/samples/_seeds.yml)**
82+
- Shows how to test a column on a seed
83+
84+
**Seed selection syntax [samples](seeds/seed_selection_syntax.md)**
85+
- Commands for running seeds including `seed`, `build`, and using `--full-refresh`
86+
87+
## Incremental Models
88+
89+
**Incremental model [samples](../models/_samples/incremental/example_incremental_model.sql)**
90+
- Example incremental model which filters records based on timestamp. Also includes sync_all_columns
91+
92+
**Incremental model with unique key [samples](../models/_samples/incremental/example_incremental_model_with_unique_key.sql)**
93+
- Example incremental model which includes the unique_id configuration to ensure there are no duplicate reocrds
94+
95+
**Incremental model without a timestamp column [samples](../models/_samples/incremental/example_incremental_model_no_timestamp.sql)**
96+
- Example incremental model which filters records based on an ID
97+
98+
**Incremental model with relative start and end dates to filter data [samples](../models/_samples/incremental/example_incremental_model_relative_start_and_end_dates.sql)**
99+
- Example incremental model which filters records based on a relative timeframe
100+
101+
**Incremental model using project variables to define lookback window [samples](../models/_samples/incremental/example_incremental_model_using_project_variable_lookback_window.sql)**
102+
- Example incremental model which filters records using a timestamp, but determining the window of data to process based on project variables
103+
104+
**Source data that incremental models are built upon [samples](../models/_samples/incremental/example_source_for_incremental.sql)**
105+
- The "source" data that the incremental models are built on top of. The "source" dataset will have a record for every second (up until the current timestamp) in the current month
106+
- This allows the source table to always have more data everytime we query it (which also explains why the source is confiugred as a view)
107+
- To use the incremental models downstream of this "source" model, just build the "source" model once and then you can run any of the downstream incremental models as many times as you'd like
108+
109+
## Snapshots
110+
111+
**Example snapshot [samples](../snapshots/_samples/example_orders_snapshot.sql)**
112+
- Example snapshot using the timestamp strategy
113+
114+
**Example snapshot with generate_schema macro [samples](../snapshots/_samples/example_generate_schema_snapshot.sql)**
115+
- Example snapshot that sets the schema using the generate_schema macro. This allows the snapshot to go into a development schema when in the development environment
116+
117+
**Example snapshot using check strategy [samples](../snapshots/_samples/example_check_snapshot.sql)**
118+
- Example snapshot using the check strategy
119+
120+
**Example model showing how to join snapshots [samples](../models/_samples/snapshot/example_join_snapshots.sql)**
121+
- Example model which shows some of the complexity of joining snapshots
122+
123+
**Testing and documenting snapshots [samples](../snapshots/_samples/_example__snapshots.yml)**
124+
- Shows how to test and document snapshots
125+
126+
## Python Models
127+
128+
**Simple python model using ref [samples](../models/_samples/python/py01__python_builtins__describe.py)**
129+
- Creates python model using ref and builtin python describe
130+
131+
**Python model using target variable [samples](../models/_samples/python/py02__use_variables__customers_limit_10.py)**
132+
- Creates python model and uses target variable
133+
134+
**Python model using and creating another python function [samples](../models/_samples/python/py03__define_function__payment_glitch.py)**
135+
- Creates python model which uses another python function
136+
137+
**Python model using and creating a Snowpark UDF [samples](../models/_samples/python/py04__add_udf_function__payment_glitch.py)**
138+
- Creates python model which creates and uses a Snowpark UDF
139+
140+
**YAML file for python models [samples](../models/_samples/python/_python__models.yml)**
141+
- YAML file for python models which adds configurations for python models, including target variable
142+
143+
**Pyhon model with pypi package [samples](python/py03__import_pypi_package__holiday.py)**
144+
- Creates python model which uses a pypi package. In the analysis folder because it takes a while to build
145+
146+
## Model Governance
147+
148+
**Example v1 of a model which is set as private in the finance group [samples](../models/_samples/model_governance/example_private_finance_model_v1.sql)**
149+
- Example v1 of a model which is set as private in the finance group. The configurations are in the `_model_governance__models.yml` file
150+
151+
**Example model which is set as private in the finance group [samples](../models/_samples/model_governance/example_private_finance_model_v2.sql)**
152+
- Example v2 of model which is set as private in the finance group. The configurations are in the `_model_governance__models.yml` file
153+
154+
**Example model selecting from v1 of a model [samples](../models/_samples/model_governance/example_selecting_from_old_version_of_private_model.sql)**
155+
- Example model selecting from v1 of a model. The configurations are in the `_model_governance__models.yml` file
156+
157+
**Example model selecting from most recent version of a model [samples](../models/_samples/model_governance/example_selecting_from_private_model.sql)**
158+
- Example model selecting from current version of a model. The configurations are in the `_model_governance__models.yml` file
159+
160+
**YAML file for model governance [samples](../models/_samples/model_governance/_model_governance__models.yml)**
161+
- YAML file which sets group, access, contract, and versions of models
162+
163+
## Macros
164+
165+
**Macro using audit_helper to audit a model [samples](../macros/_samples/audit_helper/audit_dim_customers.sql)**
166+
- Macro which audits the dim_customers model to dim_customers in production
167+
168+
**Custom schema macros [samples](custom_macros/custom_schema_configuration.md)**
169+
- Markdown file which has lots of different macros in it to customize the way generate schema works in the dbt project
170+
171+
**Custom alias macros [samples](custom_macros/custom_alias_configuration.md)**
172+
- Markdown file which has lots of different macros in it to customize the way generate alias works in the dbt project
173+
174+
## Tags
175+
176+
**Tag selection syntax [samples](tags/tag_selection_syntax.md)**
177+
178+
**Set tags in dbt_project [samples](../dbt_project.yml)**
179+
180+
## Node Selection Syntax
181+
182+
**Model selection syntax [samples](node_selection_syntax/model_selection_syntax.md)**
183+
184+
**Seed selection syntax [samples](node_selection_syntax/seed_selection_syntax.md)**
185+
186+
**Source selection syntax [samples](node_selection_syntax/source_selection_syntax.md)**
187+
188+
**Tag selection syntax [samples](node_selection_syntax/tag_selection_syntax.md)**
189+
190+
**Test selection syntax [samples](node_selection_syntax/test_selection_syntax.md)**
191+
192+
## Helpful Packages
193+
194+
### dbt_codegen
195+
196+
**Generate base model [samples](dbt_codegen/generate_base_model.sql)**
197+
- How to use generate_base_model to create the staging model for a source
198+
199+
**Generate model import CTEs [samples](dbt_codegen/generate_model_import_ctes.sql)**
200+
- Shows how to use generate_model_import_ctes to clean up a model
201+
202+
**Generate model yaml [samples](dbt_codegen/generate_model_yaml.sql)**
203+
- How to use generate_model_yaml to create the yaml for a model
204+
205+
**Generate source [samples](dbt_codegen/generate_source.sql)**
206+
- Shows how to generate the source yaml for a given database and schema
207+
208+
### dbt_utils
209+
210+
**Date spine [samples](dbt_utils/date_spine.sql)**
211+
212+
**Get column values [samples](dbt_utils/get_column_values.sql)**
213+
214+
**Pivot [samples](dbt_utils/pivot.sql)**
215+
216+
217+
### dbt_project_evaluator
218+
219+
**Run dbt project evaluator [samples](dbt_project_evaluator/syntax_run_package.md)**
220+
- Syntax to run the dbt project evaluator package
221+
222+
### dbt_audit_helper
223+
224+
**Compare queries [samples](audit_helper/compare_queries.sql)**
225+
226+
**Compare relation columns [samples](audit_helper/compare_relation_columns.sql)**
227+
228+
**Compare relations [samples](audit_helper/compare_relations.sql)**
229+
230+
### dbt_artifacts
231+
232+
**Run dbt artifacts [samples](dbt_artifacts/syntax_run_package.md)**
233+
- Syntax to run the dbt artifacts package
234+
235+
**Query dbt invocations [samples](dbt_artifacts/dbt_artifacts_fct_dbt__invocations.sql)**
236+
- Query to view dbt invocations which gets created as a model from the dbt artifacts package
237+
238+
**Query model executions [samples](dbt_artifacts/dbt_artifacts_fct_dbt__model_executions.sql)**
239+
- Query to view each model execution which gets created as a model from the dbt artifacts package
240+
241+
**On run end hook for dbt_artifacts [samples](../dbt_project.yml)**
242+
- Only runs dbt_artifacts on-run-end only when the target variable is set to prod
243+
244+
245+
## Deployment
246+
247+
**Daily Production Job [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/38569)**
248+
- Standard dbt build job scheduled to run once a day (but the schedule is turned off)
249+
250+
**Sample Hourly Job [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/347072)**
251+
- Shows how to create a job using tag selection syntax, exclude syntax, and scheduled to run hourly (though the schedule is turned off)
252+
253+
**Sample Incremental Job Every 30 Minutes Except Sunday [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/365207)**
254+
- Shows incremental job (not a full refresh) which is scheduled every 30 mintues except Sunday (schedule turned off). This is because on Sunday we want to run a full refresh once
255+
256+
**Sample Incremental Job Every 30 Minutes Sunday [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/365219)**
257+
- Shows incremental job (not a full refresh) which is scheduled every 30 mintues on Sunday. Does not run from 5am to 8am on Sunday because we have a full refresh job running on Sunday at 5am
258+
259+
**Sample Full Refresh Job Sundays [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/365211)**
260+
- Shows incremental job with a full refresh which is run at 5am on Sunday (schedule turned off). The other two incremental jobs work around this job so they don't run at the same time.
261+
262+
**Daily Staging Job [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/368562)**
263+
- Standard dbt build job in the staging environment run once a day (but the schedule is turned off)
264+
265+
**CI Job [url](https://cloud.getdbt.com/deploy/26712/projects/48031/jobs/41092)**
266+
- Standard CI job using dbt build --select state:modified+ to only build models you've modified in a PR and anything downstream of those models
267+
268+
269+
## dbt Cloud API v2
270+
271+
**Trigger a dbt Cloud job using the API [samples](dbt_cloud_api_v2/trigger_job.py)**
272+
273+
## Other
274+
275+
### Working with JSON Columns in Snowflake
276+
277+
**Snowflake flatten JSON [samples](json/snowflake_flatten_json.sql)**
278+
- Snowflake functionality to demo how SQL can be used to parse json in a single column
279+
280+
**Snowflake identify key value pair [samples](json/snowflake_identify_value_key_pairs.sql)**
281+
- Snowflake functionality to provide you with every key value pair using Snowflake functionality

0 commit comments

Comments
 (0)