Skip to content

Commit ecded9d

Browse files
authored
Move sushi_dbt to test and replace with a self-contained sushi dbt project (#646)
1 parent d8b8836 commit ecded9d

53 files changed

Lines changed: 1227 additions & 128 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/sushi/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
)
2828

2929

30-
airflow_config = Config(scheduler=AirflowSchedulerConfig())
30+
airflow_config = Config(**{"scheduler": AirflowSchedulerConfig()})
3131

3232

3333
airflow_config_docker = Config(
34-
scheduler=AirflowSchedulerConfig(airflow_url="http://airflow-webserver:8080/"),
34+
**{"scheduler": AirflowSchedulerConfig(airflow_url="http://airflow-webserver:8080/")},
3535
)

examples/sushi_dbt/dbt_project.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,13 @@ clean-targets: # directories to be removed by `dbt clean`
1616
- "target"
1717
- "dbt_packages"
1818

19-
# Configuring models
20-
# Full documentation: https://docs.getdbt.com/docs/configuring-models
21-
2219
models:
2320
+start: Jan 1 2022
2421
sushi:
2522
+materialized: table
26-
+pre-hook:
27-
- '{{ log("pre-hook") }}'
28-
+post-hook:
29-
- '{{ log("post-hook") }}'
30-
customers:
31-
+materialized: table
3223

3324
seeds:
34-
sushi:
35-
+pre-hook:
36-
- '{{ log("pre-hook") }}'
37-
+post-hook:
38-
- '{{ log("post-hook") }}'
25+
+schema: raw
3926

4027
vars:
4128
top_waiters:limit: 10
42-
'top_waiters:revenue': "revenue"
43-
44-
# The following are only used for testing purposes
45-
customers:boo: ["a", "b"]
46-
47-
customers:
48-
some_var: ["foo", "bar"]
49-
'customers:bla': false
50-
'customers:customer_id': "customer_id"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{
2+
config(
3+
materialized='incremental',
4+
incremental_strategy='delete+insert',
5+
cluster_by=['ds'],
6+
time_column='ds',
7+
)
8+
}}
9+
10+
WITH order_total AS (
11+
SELECT
12+
oi.order_id AS order_id,
13+
SUM(oi.quantity * i.price) AS total,
14+
oi.ds AS ds
15+
FROM {{ ref('order_items') }} AS oi
16+
LEFT JOIN {{ ref('items') }} AS i
17+
ON oi.item_id = i.id AND oi.ds = i.ds
18+
{% if is_incremental() %}
19+
WHERE
20+
oi.ds > (select max(ds) from {{ this }})
21+
{% endif %}
22+
{% if sqlmesh is defined %}
23+
WHERE
24+
oi.ds BETWEEN '{{ start_ds }}' AND '{{ end_ds }}'
25+
{% endif %}
26+
GROUP BY
27+
oi.order_id,
28+
oi.ds
29+
)
30+
SELECT
31+
o.customer_id::INT AS customer_id, /* Customer id */
32+
SUM(ot.total)::DOUBLE AS revenue, /* Revenue from orders made by this customer */
33+
o.ds::TEXT AS ds /* Date */
34+
FROM {{ ref('orders') }} AS o
35+
LEFT JOIN order_total AS ot
36+
ON o.id = ot.order_id AND o.ds = ot.ds
37+
{% if is_incremental() %}
38+
WHERE
39+
o.ds > (select max(ds) from {{ this }})
40+
{% endif %}
41+
{% if sqlmesh is defined %}
42+
WHERE
43+
o.ds BETWEEN '{{ start_ds }}' AND '{{ end_ds }}'
44+
{% endif %}
45+
GROUP BY
46+
o.customer_id,
47+
o.ds
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT DISTINCT
2+
customer_id::INT AS customer_id
3+
FROM {{ ref('orders') }} as o
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
version: 2
22

33
models:
4+
- name: customers
5+
- name: customer_revenue_by_day
46
- name: top_waiters
57
- name: waiters
68
- name: waiter_as_customer_by_day
79
- name: waiter_revenue_by_day
8-
9-
sources:
10-
- name: raw
11-
schema: raw
12-
tables:
13-
- name: items
14-
- name: orders
15-
- name: order_items

examples/sushi_dbt/models/top_waiters.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
SELECT
88
waiter_id::INT AS waiter_id,
9-
revenue::DOUBLE AS {{ var("top_waiters:revenue") }}
9+
revenue::DOUBLE AS revenue
1010
FROM {{ ref('waiter_revenue_by_day') }}
1111
WHERE
1212
ds = (

examples/sushi_dbt/models/waiter_revenue_by_day.sql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
)
88
}}
99

10-
{{ log_value(5) }}
11-
{{ log(adapter.dispatch('current_engine', 'customers')()) }}
12-
1310
SELECT
1411
o.waiter_id::INT AS waiter_id, /* Waiter id */
1512
SUM(oi.quantity * i.price)::DOUBLE AS revenue, /* Revenue from orders taken by this waiter */
1613
o.ds::TEXT AS ds /* Date */
17-
FROM {{ source('raw', 'orders') }} AS o
18-
LEFT JOIN {{ source('raw', 'order_items') }} AS oi
14+
FROM {{ ref('orders') }} AS o
15+
LEFT JOIN {{ ref('order_items') }} AS oi
1916
ON o.id = oi.order_id AND o.ds = oi.ds
20-
LEFT JOIN {{ source('raw', 'items') }} AS i
17+
LEFT JOIN {{ ref('items') }} AS i
2118
ON oi.item_id = i.id AND oi.ds = i.ds
2219
{% if is_incremental() %}
2320
WHERE

examples/sushi_dbt/models/waiters.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
SELECT DISTINCT
88
waiter_id::INT AS waiter_id,
99
ds::TEXT AS ds
10-
FROM {{ source('raw', 'orders') }}
10+
FROM {{ ref('orders') }}
1111
{{ incremental_by_time('ds', 'ds') }}
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +0,0 @@
1-
version: 2
2-
3-
models:
4-
- name: customers
5-
- name: customer_revenue_by_day
6-
7-
sources:
8-
- name: raw
9-
schema: raw
10-
tables:
11-
- name: items
12-
- name: orders
13-
- name: order_items

0 commit comments

Comments
 (0)