-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from dbt-labs/feat/add-more-samples
Added more samples to exemplar
- Loading branch information
Showing
51 changed files
with
913 additions
and
23 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Note: the easiest way to run this is through this Hex app because it has the token stored as a secret | ||
# https://app.hex.tech/fishtown/hex/be772c9d-fce1-4994-9bb9-423429318943/draft/logic | ||
|
||
import requests | ||
|
||
account_id = 26712 | ||
job_id = 38569 | ||
token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
|
||
headers = { | ||
'Authorization': f'Token {token}', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
json_data = { | ||
'cause': 'Triggered from a Python Script' | ||
} | ||
|
||
response = requests.post( | ||
f'https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run', | ||
headers=headers, | ||
json=json_data | ||
) | ||
|
||
print(response) |
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,73 @@ | ||
## Some examples of helpful syntax for building models | ||
|
||
1. Build dim_customers and all children | ||
|
||
``` | ||
dbt build --select dim_customers+ | ||
``` | ||
|
||
2. Build dim_customers and all parents | ||
|
||
``` | ||
dbt build --select +dim_customers | ||
``` | ||
|
||
3. Build dim_customers and all parents and children | ||
|
||
``` | ||
dbt build --select +dim_customers+ | ||
``` | ||
|
||
4. Build dim_customers, it's first degree parents, and it's first degree children | ||
|
||
``` | ||
dbt build --select 1+dim_customers+1 | ||
``` | ||
|
||
5. Build dim_customers, it's children, and all of it's children's parents | ||
|
||
``` | ||
dbt build --select @dim_customers | ||
``` | ||
|
||
6. Build all models in the dbt_artifacts package | ||
|
||
``` | ||
dbt build --select dbt_artifacts | ||
``` | ||
|
||
7. Build all models in the marts/finance directory | ||
|
||
``` | ||
dbt build --select marts.finance | ||
``` | ||
|
||
8. Build all models in the marts/finance directory except fct_orders and it's children | ||
|
||
``` | ||
dbt build --select marts.finance --exclude fct_orders+ | ||
``` | ||
|
||
9. Build all incremental models | ||
|
||
``` | ||
dbt build --select config.materialized.incremental | ||
``` | ||
|
||
10. Build all models (and seeds and snapshots) in the selector all_models_and_tagged_snapshots | ||
|
||
``` | ||
dbt build --selector all_models_and_tagged_snapshots | ||
``` | ||
|
||
11. Build version 2 (latest version) of a model called example_private_finance_model which has an alias of example_private_finance_model | ||
|
||
``` | ||
dbt build --select example_private_finance_model | ||
``` | ||
|
||
12. Build version 1 of a model called example_private_finance_model | ||
|
||
``` | ||
dbt build --select example_private_finance_model.v1 | ||
``` |
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,20 @@ | ||
## Some examples of helpful syntax for using seeds | ||
|
||
1. Create all seeds in your warehouse without testing any | ||
|
||
``` | ||
dbt seed | ||
``` | ||
|
||
2. Build a seed named alphabet_grouping in your warehouse including testing it | ||
|
||
``` | ||
dbt build --select alphabet_grouping | ||
``` | ||
|
||
3. Full refresh your seed so that dbt will drop and recreate the object instead of truncating and inserting. | ||
This is useful when you add or remove columns from a seed | ||
|
||
``` | ||
dbt build --select alphabet_grouping --full-refresh | ||
``` |
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,54 @@ | ||
## Some examples of helpful syntax for using sources | ||
|
||
### Testing Sources | ||
|
||
1. Test all of your sources | ||
|
||
``` | ||
dbt test --select source:* | ||
``` | ||
|
||
2. Test all tables in your source named jaffle_shop | ||
|
||
``` | ||
dbt test --select source:jaffle_shop | ||
``` | ||
|
||
3. Test a specific source table named orders within your jaffle_shop source | ||
|
||
``` | ||
dbt test --select source:jaffle_shop.orders | ||
``` | ||
|
||
### Source Freshness | ||
1. Run source freshness on all of your sources | ||
|
||
``` | ||
dbt source freshness --select source:* | ||
``` | ||
|
||
2. Run source freshness on all tables in your source named jaffle_shop | ||
|
||
``` | ||
dbt source freshness --select source:jaffle_shop | ||
``` | ||
|
||
3. Run source freshness on a specific source table named orders within your jaffle_shop source | ||
|
||
``` | ||
dbt source freshness --select source:jaffle_shop.orders | ||
``` | ||
|
||
### Building (running and testing) downstream sources | ||
|
||
1. Build (run and test) all models downstream of a source named jaffle_shop | ||
|
||
``` | ||
dbt build --select source:jaffle_shop+ | ||
``` | ||
|
||
2. Build (run and test) all models downstream specific source table named orders within your jaffle_shop source | ||
|
||
``` | ||
dbt build --select source:jaffle_shop.orders+ | ||
``` |
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,25 @@ | ||
## Some examples of helpful syntax for using tags | ||
|
||
1. Build all models that have the hourly tag | ||
|
||
``` | ||
dbt build --select tag:hourly | ||
``` | ||
|
||
2. Build all models and their downstream dependencies that have the hourly tag | ||
|
||
``` | ||
dbt build --select tag:hourly+ | ||
``` | ||
|
||
3. Build all models that have both the finance tag AND the orders tag | ||
|
||
``` | ||
dbt build --select tag:hourly,tag:orders | ||
``` | ||
|
||
4. Build all models that have both the finance tag OR the orders tag | ||
|
||
``` | ||
dbt build --select tag:hourly tag:orders | ||
``` |
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,19 @@ | ||
## Some examples of helpful syntax for testing specific tests | ||
|
||
1. Test all generic tests | ||
|
||
``` | ||
dbt test --select test_type:generic | ||
``` | ||
|
||
2. Test all tests named unique | ||
|
||
``` | ||
dbt test --select test_name:unique | ||
``` | ||
|
||
3. Test a source named jaffle_shop | ||
|
||
``` | ||
dbt test --select source:jaffle_shop | ||
``` |
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
File renamed without changes.
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
File renamed without changes.
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,17 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
on_schema_change='sync_all_columns' | ||
) | ||
}} | ||
|
||
with source as ( | ||
select * from {{ ref('example_source_for_incremental') }} | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where _etl_loaded_at > (select max(_etl_loaded_at) from {{ this }}) | ||
{% endif %} | ||
) | ||
|
||
select * | ||
from source |
17 changes: 17 additions & 0 deletions
17
models/_samples/incremental/example_incremental_model_no_timestamp.sql
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,17 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
on_schema_change='sync_all_columns' | ||
) | ||
}} | ||
|
||
with source as ( | ||
select * from {{ ref('example_source_for_incremental') }} | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where event_id not in (select event_id from {{ this }}) | ||
{% endif %} | ||
) | ||
|
||
select * | ||
from source |
24 changes: 24 additions & 0 deletions
24
models/_samples/incremental/example_incremental_model_relative_start_and_end_dates.sql
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,24 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key='event_id', | ||
on_schema_change='sync_all_columns' | ||
) | ||
}} | ||
|
||
|
||
|
||
with source as ( | ||
select * from {{ ref('example_source_for_incremental') }} | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where _etl_loaded_at >= dateadd(day, -2, current_date) | ||
and _etl_loaded_at <= dateadd(day, -1, current_date) | ||
|
||
{% endif %} | ||
|
||
|
||
) | ||
|
||
select * | ||
from source |
30 changes: 30 additions & 0 deletions
30
..._samples/incremental/example_incremental_model_using_project_variable_lookback_window.sql
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,30 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key='event_id', | ||
on_schema_change='sync_all_columns' | ||
) | ||
}} | ||
|
||
with source as ( | ||
select * from {{ ref('example_source_for_incremental') }} | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where _etl_loaded_at > ( | ||
|
||
select {{ dbt.dateadd( | ||
var('incremental_lookback_period'), | ||
-var('incremental_lookback_value'), | ||
"max(_etl_loaded_at)") }} | ||
|
||
from {{ this }} | ||
) | ||
|
||
|
||
{% endif %} | ||
|
||
|
||
) | ||
|
||
select * | ||
from source |
20 changes: 20 additions & 0 deletions
20
models/_samples/incremental/example_incremental_model_with_unique_key.sql
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,20 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key='event_id', | ||
on_schema_change='sync_all_columns' | ||
) | ||
}} | ||
|
||
with source as ( | ||
select * from {{ ref('example_source_for_incremental') }} | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where _etl_loaded_at > (select {{ dbt.dateadd("hour", -3, "max(_etl_loaded_at)") }} from {{ this }}) | ||
|
||
|
||
{% endif %} | ||
) | ||
|
||
select * | ||
from source |
Oops, something went wrong.