From 28b58d94d87226a7937fa4866fc151c1d89cc524 Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Mon, 5 Dec 2022 12:39:17 -0800 Subject: [PATCH] Add sushi dbt project --- tests/projects/sushi_dbt/.gitignore | 4 ++ tests/projects/sushi_dbt/README.md | 15 +++++++ tests/projects/sushi_dbt/analyses/.gitkeep | 0 tests/projects/sushi_dbt/dbt_project.yml | 29 ++++++++++++++ tests/projects/sushi_dbt/macros/.gitkeep | 0 .../sushi_dbt/models/cleansed/customers.sql | 3 ++ .../sushi_dbt/models/cleansed/items.sql | 19 +++++++++ .../sushi_dbt/models/cleansed/order_items.sql | 20 ++++++++++ .../sushi_dbt/models/cleansed/orders.sql | 21 ++++++++++ .../sushi_dbt/models/cleansed/schema.yml | 14 +++++++ .../sushi_dbt/models/cleansed/waiters.sql | 17 ++++++++ .../models/db/customer_revenue_by_day.sql | 39 +++++++++++++++++++ tests/projects/sushi_dbt/models/db/schema.yml | 6 +++ .../sushi_dbt/models/db/top_waiters.sql | 19 +++++++++ .../models/db/waiter_revenue_by_day.sql | 25 ++++++++++++ tests/projects/sushi_dbt/seeds/.gitkeep | 0 tests/projects/sushi_dbt/snapshots/.gitkeep | 0 tests/projects/sushi_dbt/tests/.gitkeep | 0 18 files changed, 231 insertions(+) create mode 100644 tests/projects/sushi_dbt/.gitignore create mode 100644 tests/projects/sushi_dbt/README.md create mode 100644 tests/projects/sushi_dbt/analyses/.gitkeep create mode 100644 tests/projects/sushi_dbt/dbt_project.yml create mode 100644 tests/projects/sushi_dbt/macros/.gitkeep create mode 100644 tests/projects/sushi_dbt/models/cleansed/customers.sql create mode 100644 tests/projects/sushi_dbt/models/cleansed/items.sql create mode 100644 tests/projects/sushi_dbt/models/cleansed/order_items.sql create mode 100644 tests/projects/sushi_dbt/models/cleansed/orders.sql create mode 100644 tests/projects/sushi_dbt/models/cleansed/schema.yml create mode 100644 tests/projects/sushi_dbt/models/cleansed/waiters.sql create mode 100644 tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql create mode 100644 tests/projects/sushi_dbt/models/db/schema.yml create mode 100644 tests/projects/sushi_dbt/models/db/top_waiters.sql create mode 100644 tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql create mode 100644 tests/projects/sushi_dbt/seeds/.gitkeep create mode 100644 tests/projects/sushi_dbt/snapshots/.gitkeep create mode 100644 tests/projects/sushi_dbt/tests/.gitkeep diff --git a/tests/projects/sushi_dbt/.gitignore b/tests/projects/sushi_dbt/.gitignore new file mode 100644 index 0000000000..49f147cb98 --- /dev/null +++ b/tests/projects/sushi_dbt/.gitignore @@ -0,0 +1,4 @@ + +target/ +dbt_packages/ +logs/ diff --git a/tests/projects/sushi_dbt/README.md b/tests/projects/sushi_dbt/README.md new file mode 100644 index 0000000000..7874ac842b --- /dev/null +++ b/tests/projects/sushi_dbt/README.md @@ -0,0 +1,15 @@ +Welcome to your new dbt project! + +### Using the starter project + +Try running the following commands: +- dbt run +- dbt test + + +### Resources: +- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction) +- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers +- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support +- Find [dbt events](https://events.getdbt.com) near you +- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices diff --git a/tests/projects/sushi_dbt/analyses/.gitkeep b/tests/projects/sushi_dbt/analyses/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/projects/sushi_dbt/dbt_project.yml b/tests/projects/sushi_dbt/dbt_project.yml new file mode 100644 index 0000000000..379c4a5967 --- /dev/null +++ b/tests/projects/sushi_dbt/dbt_project.yml @@ -0,0 +1,29 @@ + +name: 'sushi' +version: '1.0.0' +config-version: 2 +profile: 'sushi' + +model-paths: ["models"] +analysis-paths: ["analyses"] +test-paths: ["tests"] +seed-paths: ["seeds"] +macro-paths: ["macros"] +snapshot-paths: ["snapshots"] + +target-path: "target" # directory which will store compiled SQL files +clean-targets: # directories to be removed by `dbt clean` + - "target" + - "dbt_packages" + +# Configuring models +# Full documentation: https://docs.getdbt.com/docs/configuring-models + +models: + sushi: + cleansed: + +schema: cleansed + +materialized: table + db: + +schema: db + +materialized: table diff --git a/tests/projects/sushi_dbt/macros/.gitkeep b/tests/projects/sushi_dbt/macros/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/projects/sushi_dbt/models/cleansed/customers.sql b/tests/projects/sushi_dbt/models/cleansed/customers.sql new file mode 100644 index 0000000000..0b6da56180 --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/customers.sql @@ -0,0 +1,3 @@ +SELECT DISTINCT + customer_id::INT AS customer_id +FROM {{ source('raw', 'orders') }} \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/cleansed/items.sql b/tests/projects/sushi_dbt/models/cleansed/items.sql new file mode 100644 index 0000000000..f7e5f03d93 --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/items.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'], + ) +}} + +SELECT + id::DOUBLE AS id, /* Primary key */ + name::TEXT AS name, /* Name of the sushi */ + price::DOUBLE AS price, /* Price of the sushi */ + ds::TEXT AS ds /* Date */ +FROM {{ source('raw', 'items') }} +{% if is_incremental() %} +WHERE + ds > (select max(ds) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/cleansed/order_items.sql b/tests/projects/sushi_dbt/models/cleansed/order_items.sql new file mode 100644 index 0000000000..ec69cc4d06 --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/order_items.sql @@ -0,0 +1,20 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'] + ) +}} + +SELECT + id::INT AS id, /* Primary key */ + order_id::INT AS order_id, /* Order id */ + item_id::INT AS item_id, /* Item id */ + quantity::INT AS quantity, /* Quantity of items ordered */ + ds::TEXT AS ds /* Date of order */ +FROM {{ source('raw', 'order_items') }} +{% if is_incremental() %} +WHERE + ds > (select max(ds) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/cleansed/orders.sql b/tests/projects/sushi_dbt/models/cleansed/orders.sql new file mode 100644 index 0000000000..c9b93983f6 --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/orders.sql @@ -0,0 +1,21 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'] + ) +}} + +SELECT + id::INT AS id, /* Primary key */ + customer_id::INT AS customer_id, /* Id of customer who made the order */ + waiter_id::INT AS waiter_id, /* Id of waiter who took the order */ + start_ts::TEXT AS start_ts, /* Start timestamp */ + end_ts::TEXT AS end_ts, /* End timestamp */ + ds::TEXT AS ds /* Date of order */ +FROM {{ source('raw', 'orders') }} +{% if is_incremental() %} +WHERE + ds > (select max(ds) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/cleansed/schema.yml b/tests/projects/sushi_dbt/models/cleansed/schema.yml new file mode 100644 index 0000000000..903f3a7abc --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/schema.yml @@ -0,0 +1,14 @@ +version: 2 + +models: + - name: items + - name: orders + - name: order_items + - name: customers + - name: waiters +sources: + - name: raw + tables: + - name: items + - name: orders + - name: order_items \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/cleansed/waiters.sql b/tests/projects/sushi_dbt/models/cleansed/waiters.sql new file mode 100644 index 0000000000..159970a562 --- /dev/null +++ b/tests/projects/sushi_dbt/models/cleansed/waiters.sql @@ -0,0 +1,17 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'] + ) +}} + +SELECT DISTINCT + waiter_id::INT AS waiter_id, + ds::TEXT AS ds +FROM {{ source('raw', 'orders') }} +{% if is_incremental() %} +WHERE + ds > (select max(ds) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql b/tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql new file mode 100644 index 0000000000..76f38a82d4 --- /dev/null +++ b/tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql @@ -0,0 +1,39 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'] + ) +}} + +WITH order_total AS ( + SELECT + oi.order_id AS order_id, + SUM(oi.quantity * i.price) AS total, + oi.ds AS ds + FROM {{ ref('order_items') }} AS oi + LEFT JOIN {{ ref('items') }} AS i + ON oi.item_id = i.id AND oi.ds = i.ds +{% if is_incremental() %} + WHERE + oi.ds > (select max(oi.ds) from {{ this }}) +{% endif %} + GROUP BY + oi.order_id, + oi.ds +) +SELECT + o.customer_id::INT AS customer_id, /* Customer id */ + SUM(ot.total)::DOUBLE AS revenue, /* Revenue from orders made by this customer */ + o.ds::TEXT AS ds /* Date */ +FROM {{ ref('orders') }} AS o +LEFT JOIN order_total AS ot + ON o.id = ot.order_id AND o.ds = ot.ds +{% if is_incremental() %} +WHERE + o.ds > (select max(o.ds) from {{ this }}) +{% endif %} +GROUP BY + o.customer_id, + o.ds \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/db/schema.yml b/tests/projects/sushi_dbt/models/db/schema.yml new file mode 100644 index 0000000000..849dccb801 --- /dev/null +++ b/tests/projects/sushi_dbt/models/db/schema.yml @@ -0,0 +1,6 @@ +version: 2 + +models: + - name: customer_revenue_by_day + - name: top_waiters + - name: waiter_revenue_by_day \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/db/top_waiters.sql b/tests/projects/sushi_dbt/models/db/top_waiters.sql new file mode 100644 index 0000000000..b1c4885328 --- /dev/null +++ b/tests/projects/sushi_dbt/models/db/top_waiters.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='view' + ) +}} + +SELECT + waiter_id::INT AS waiter_id, + revenue::DOUBLE AS revenue +FROM {{ ref('waiter_revenue_by_day') }} +WHERE + ds = ( + SELECT + MAX(ds) + FROM {{ ref('waiter_revenue_by_day') }} + ) +ORDER BY + revenue DESC +LIMIT 10 \ No newline at end of file diff --git a/tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql b/tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql new file mode 100644 index 0000000000..482a835554 --- /dev/null +++ b/tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql @@ -0,0 +1,25 @@ +{{ + config( + materialized='incremental', + incremental_strategy='delete+insert', + cluster_by=['ds'], + unique_key=['ds'] + ) +}} + +SELECT + o.waiter_id::INT AS waiter_id, /* Waiter id */ + SUM(oi.quantity * i.price)::DOUBLE AS revenue, /* Revenue from orders taken by this waiter */ + o.ds::TEXT AS ds /* Date */ +FROM {{ ref('orders') }} AS o +LEFT JOIN {{ ref('order_items') }} AS oi + ON o.id = oi.order_id AND o.ds = oi.ds +LEFT JOIN {{ ref('items') }} AS i + ON oi.item_id = i.id AND oi.ds = i.ds +{% if is_incremental() %} + WHERE + o.ds > (select max(o.ds) from {{ this }}) +{% endif %} +GROUP BY + o.waiter_id, + o.ds \ No newline at end of file diff --git a/tests/projects/sushi_dbt/seeds/.gitkeep b/tests/projects/sushi_dbt/seeds/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/projects/sushi_dbt/snapshots/.gitkeep b/tests/projects/sushi_dbt/snapshots/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/projects/sushi_dbt/tests/.gitkeep b/tests/projects/sushi_dbt/tests/.gitkeep new file mode 100644 index 0000000000..e69de29bb2