Skip to content

Commit fa94c84

Browse files
committed
Added some examples for dbt materializations and macros
1 parent dbc17ea commit fa94c84

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% macro hash_arguments(args) -%}
2+
ORA_HASH({%- for arg in args -%}
3+
coalesce(cast({{ arg }} as varchar(50) ), '')
4+
{% if not loop.last %} || '|' || {% endif %}
5+
{%- endfor -%})
6+
{%- endmacro %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{config(materialized='table')}}
2+
WITH direct_sales_promo_cost AS (
3+
SELECT s.prod_id,
4+
s.quantity_sold,
5+
s.amount_sold,
6+
s.time_id,
7+
c.channel_desc,
8+
p.promo_name,
9+
p.promo_cost
10+
FROM {{ source('sh_database', 'sales') }} s,
11+
{{ source('sh_database', 'promotions') }} p,
12+
{{ source('sh_database', 'channels') }} c
13+
WHERE s.channel_id = 3
14+
AND s.promo_id = p.promo_id
15+
AND s.channel_id = c.channel_id
16+
)
17+
SELECT * FROM direct_sales_promo_cost
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{config(materialized='incremental')}}
2+
WITH direct_sales_promo_cost AS (
3+
SELECT s.prod_id,
4+
s.quantity_sold,
5+
s.amount_sold,
6+
s.time_id,
7+
c.channel_desc,
8+
p.promo_name,
9+
p.promo_cost
10+
FROM {{ source('sh_database', 'sales') }} s,
11+
{{ source('sh_database', 'promotions') }} p,
12+
{{ source('sh_database', 'channels') }} c
13+
WHERE s.channel_id = 3
14+
AND s.promo_id = p.promo_id
15+
AND s.channel_id = c.channel_id
16+
{% if is_incremental() %}
17+
AND s.time_id > (SELECT MAX(time_id) FROM {{ this }})
18+
{% endif %}
19+
)
20+
SELECT * FROM direct_sales_promo_cost
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{config(materialized='incremental', unique_key='group_id')}}
2+
WITH direct_sales_promo_cost AS (
3+
SELECT s.prod_id,
4+
s.quantity_sold,
5+
s.amount_sold,
6+
s.time_id,
7+
c.channel_desc,
8+
p.promo_name,
9+
p.promo_cost,
10+
{{ hash_arguments(['s.prod_id', 's.quantity_sold', 's.time_id', 'p.promo_name']) }} AS group_id
11+
FROM {{ source('sh_database', 'sales') }} s,
12+
{{ source('sh_database', 'promotions') }} p,
13+
{{ source('sh_database', 'channels') }} c
14+
WHERE s.channel_id = 3
15+
AND s.promo_id = p.promo_id
16+
AND s.channel_id = c.channel_id
17+
{% if is_incremental() %}
18+
AND s.time_id > (SELECT MAX(time_id) FROM {{ this }})
19+
{% endif %}
20+
)
21+
SELECT * FROM direct_sales_promo_cost

0 commit comments

Comments
 (0)