-
Notifications
You must be signed in to change notification settings - Fork 380
Add sushi dbt project #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| target/ | ||
| dbt_packages/ | ||
| logs/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
39
tests/projects/sushi_dbt/models/db/customer_revenue_by_day.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
25
tests/projects/sushi_dbt/models/db/waiter_revenue_by_day.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.