Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/projects/sushi_dbt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_packages/
logs/
15 changes: 15 additions & 0 deletions tests/projects/sushi_dbt/README.md
Original file line number Diff line number Diff line change
@@ -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
Empty file.
29 changes: 29 additions & 0 deletions tests/projects/sushi_dbt/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file.
3 changes: 3 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT DISTINCT
customer_id::INT AS customer_id
FROM {{ source('raw', 'orders') }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are no raw orders anymore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you suggest loading raw data for dbt projects in the meantime until we integrate our python models with it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure yet

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we can handle that later. For now, I'm only using this to test my config parser.

19 changes: 19 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/items.sql
Original file line number Diff line number Diff line change
@@ -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 %}
20 changes: 20 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/order_items.sql
Original file line number Diff line number Diff line change
@@ -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 %}
21 changes: 21 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/orders.sql
Original file line number Diff line number Diff line change
@@ -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 %}
14 changes: 14 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/schema.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/projects/sushi_dbt/models/cleansed/waiters.sql
Original file line number Diff line number Diff line change
@@ -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 %}
39 changes: 39 additions & 0 deletions tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/projects/sushi_dbt/models/db/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2

models:
- name: customer_revenue_by_day
- name: top_waiters
- name: waiter_revenue_by_day
19 changes: 19 additions & 0 deletions tests/projects/sushi_dbt/models/db/top_waiters.sql
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Empty file.
Empty file.