Skip to content

Commit d069735

Browse files
WIP
1 parent 932d875 commit d069735

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

learn-dbt/data/country_codes.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
country_code,country_name
2+
US,United States
3+
MX,Mexico
4+
GB,Great Britain

learn-dbt/dbt_project.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ clean-targets: # directories to be removed by `dbt clean`
2323
- "target"
2424
- "dbt_modules"
2525

26+
on-run-start:
27+
- "create table if not exists audit (model text, state text, time timestamp_ltz)"
28+
29+
on-run-end:
30+
- 'grant usage on schema analytics.dbt to role analyst'
31+
- 'grant select on all tables in schema analytics.dbt to role analyst'
32+
- 'grant select on all views in schema analytics.dbt to role analyst'
33+
2634

2735
# Configuring models
2836
# Full documentation: https://docs.getdbt.com/docs/configuring-models
@@ -39,3 +47,4 @@ models:
3947
my_first_variable: True
4048
my_second_variable: 2020
4149
my_third_variable: 1
50+
pre-hook: "insert into dbt.audit (model, state, time) values ('{{this.name}}', 'starting model deployment', current_timestamp)"

learn-dbt/models/example/my_first_dbt_model.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
with source_data as (
1212

13-
select 1 as id
13+
select 1 as id, 'NY' as state, '2020-02-01 00:01:00.000'::timestamp as updated_at
1414
union all
15-
select null as id
15+
select null as id, 'CT' as state, '2020-01-01 00:00:00.000'::timestamp as updated_at
1616
union all
17-
select 3 as id
17+
select 4 as id, 'VT' as state, '2020-01-01 00:00:00.000'::timestamp as updated_at
18+
union all
19+
select 5 as id, 'NJ' as state, '2020-01-01 00:00:00.000'::timestamp as updated_at
1820

1921
)
2022

learn-dbt/models/example/schema.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ models:
3939
tests:
4040
- accepted_values:
4141
values: ['BUILDING', 'AUTOMOBILE', 'MACHINERY', 'HOUSEHOLD', 'FURNITURE']
42+
43+
sources:
44+
- name: sample
45+
database: snowflake_sample_data # Tell dbt to look for the source in the "raw" database
46+
schema: tpch_sf1
47+
tables:
48+
- name: customer
49+
- name: orders

learn-dbt/models/example/snowflake_customer_purchases.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ SELECT
33
c.c_name,
44
c.c_nationkey as nation,
55
sum(o.o_totalprice) as total_order_price
6-
from "SNOWFLAKE_SAMPLE_DATA"."TPCH_SF1"."CUSTOMER" c
7-
LEFT JOIN "SNOWFLAKE_SAMPLE_DATA"."TPCH_SF1"."ORDERS" o
6+
from {{ source('sample', 'customer') }} c
7+
LEFT JOIN {{ source('sample', 'orders') }} o
88
ON c.c_custkey = o.o_custkey
99

1010
group by
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% snapshot first_model_snapshot %}
2+
{{
3+
config(
4+
target_database='analytics',
5+
target_schema='snapshots',
6+
unique_key='id',
7+
8+
strategy='timestamp',
9+
updated_at='updated_at',
10+
)
11+
}}
12+
13+
-- Pro-Tip: Use sources in snapshots!
14+
select * from {{ ref('my_first_dbt_model') }}
15+
16+
{% endsnapshot %}

0 commit comments

Comments
 (0)