Skip to content

Commit

Permalink
Merge pull request #66 from dbt-labs/feat/add-more-samples
Browse files Browse the repository at this point in the history
Added more samples to exemplar
  • Loading branch information
jeremyholtzman authored Jun 29, 2023
2 parents eb4547d + 221908b commit 9e48f51
Show file tree
Hide file tree
Showing 51 changed files with 913 additions and 23 deletions.
25 changes: 25 additions & 0 deletions _samples/dbt_cloud_api_v2/trigger_job.py
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)
73 changes: 73 additions & 0 deletions _samples/node_selection_syntax/model_selection_syntax.md
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
```
20 changes: 20 additions & 0 deletions _samples/node_selection_syntax/seed_selection_syntax.md
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
```
54 changes: 54 additions & 0 deletions _samples/node_selection_syntax/source_selection_syntax.md
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+
```
25 changes: 25 additions & 0 deletions _samples/node_selection_syntax/tag_selection_syntax.md
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
```
19 changes: 19 additions & 0 deletions _samples/node_selection_syntax/test_selection_syntax.md
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
```
2 changes: 0 additions & 2 deletions _samples/tags/tag_selection_syntax.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Some examples of helpful syntax for using tags

### Testing Sources

1. Build all models that have the hourly tag

```
Expand Down
18 changes: 13 additions & 5 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ clean-targets: # directories to be removed by `dbt clean`
vars:
example_variable: foo
example_target_snapshot_schema: "{{ target.schema if target.name == 'dev' else 'prod_snapshot' }}"
incremental_lookback_value: 3
incremental_lookback_period: 'hour'
future_proof_date: '9999-12-31'

# on-run-end:
# - "{% if target.name == 'prod' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"
on-run-end:
- "{% if target.name == 'prod' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"


# Configuring models
Expand All @@ -39,11 +42,17 @@ models:
marts:
+materialized: table
+tags: ['tag']
finance:
+group: finance
marketing:
+group: marketing
operations:
+group: operations
intermediate:
+materialized: view
staging:
+materialized: view
examples:
_samples:
+materialized: table
staging:
jaffle_shop:
Expand All @@ -57,7 +66,6 @@ models:

tests:
rapid_onboarding_exemplar:
examples:
_samples:
staging:
+store_failures: "{{ true if target.name == 'prod' else false }}"

17 changes: 17 additions & 0 deletions models/_samples/incremental/example_incremental_model.sql
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
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
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
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
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
Loading

0 comments on commit 9e48f51

Please sign in to comment.