-
Notifications
You must be signed in to change notification settings - Fork 1
Jaggi branch #15
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
base: main
Are you sure you want to change the base?
Jaggi branch #15
Changes from all commits
aa0dcd9
e97c3d0
ccb1102
7e7b29f
44e9a11
d5a1615
e4b8594
dfb35c1
4472a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| select | ||
| count(*) as failures, | ||
| count(*) != 0 as should_warn, | ||
| count(*) != 0 as should_error | ||
| from ( | ||
|
|
||
| select | ||
| order_id as unique_field, | ||
| count(*) as n_records | ||
|
|
||
| from DBT_TRAINING.dbt_jkavuru.stg_jaffle_shop__orders | ||
| where order_id is not null | ||
| group by order_id | ||
| having count(*) > 1 | ||
|
|
||
| ) dbt_internal_test | ||
|
|
||
| /************************************************ */ | ||
|
|
||
| SELECT order_id, COUNT(*) | ||
| FROM DBT_TRAINING.dbt_jkavuru.stg_jaffle_shop__orders | ||
| GROUP BY order_id | ||
| HAVING COUNT(*) > 1; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
|
|
||
| CREATE TABLE DBT_TRAINING.DBT_JKAVURU.customers | ||
| ( | ||
| id NUMBER(9) PRIMARY KEY, | ||
| first_name VARCHAR(10) NOT NULL, | ||
| last_name VARCHAR(10) NOT NULL | ||
|
|
||
| ); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
|
|
||
| select id as customer_id, first_name, last_name | ||
|
|
||
| from DBT_TRAINING.DBT_JKAVURU.customers | ||
|
|
||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| with orders as ( | ||
| select * from {{ ref ('stg_jaffle_shop__orders' )}} | ||
| ), | ||
|
|
||
| payments as ( | ||
| select * from {{ ref ('stg_stripe__payments') }} | ||
| ), | ||
|
|
||
|
|
||
| order_payments as ( | ||
| select | ||
| order_id, | ||
| payments.status as payment_status, | ||
| sum (case when status = 'success' then amount * 100 end) as amount, | ||
| sum (case when status = 'fail' then amount * 100 end) as amount_failed, | ||
| sum (case when status is null then 0 else amount * 100 end) as amount_total | ||
| from payments | ||
| group by 1,2 | ||
| ), | ||
|
|
||
| final as ( | ||
|
|
||
| select | ||
| orders.order_id, | ||
| orders.customer_id, | ||
| orders.order_date, | ||
| coalesce (order_payments.amount, 0) as amount, | ||
| order_payments.payment_status as payment_status1 | ||
| from orders | ||
| left join order_payments using (order_id) | ||
| ) | ||
|
|
||
| select * from final order by 1 asc | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| version: 2 | ||
|
|
||
| sources: | ||
| - name: jaffle_shop | ||
| database: raw | ||
| schema: jaffle_shop | ||
| freshness: # make this a little more strict | ||
| warn_after: { count: 24, period: hour } | ||
| error_after: { count: 1000, period: day } #Jaggi > increased from 12 to 9200 # | ||
| loaded_at_field: _etl_loaded_at | ||
|
|
||
| tables: | ||
| - name: customers | ||
| freshness: null #Jaggi, changed the freshness to null for customers model. | ||
| - name: orders |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This model could be removed from the project as it's really just a placeholder for the project. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,31 @@ | ||
|
|
||
| /* | ||
| Welcome to your first dbt model! | ||
| Did you know that you can also configure models directly within SQL files? | ||
| This will override configurations stated in dbt_project.yml | ||
|
|
||
| Try changing "table" to "view" below | ||
| */ | ||
| {{ config(materialized="table") }} | ||
|
|
||
| {{ config(materialized='table') }} | ||
|
|
||
| with source_data as ( | ||
| with | ||
| source_data as ( | ||
|
|
||
| select 1 as id | ||
| union all | ||
| select null as id | ||
| select 1 as id, 'Jaggi' as fname, 'Krishna' as lname | ||
| union all | ||
| select 2 as id, 'Todd' as fname, 'Graham' as lname | ||
| union all | ||
| select 3 as id, 'Penny' as fname, 'Davis' as lname | ||
| union all | ||
| select null as id, 'Kelly' as fname, 'Greer' as lname | ||
|
|
||
| ) | ||
| ) | ||
|
|
||
| select * | ||
| from source_data | ||
| from | ||
| source_data | ||
|
|
||
| /* | ||
| /* | ||
| Uncomment the line below to remove records with null `id` values | ||
| */ | ||
|
|
||
| -- where id is not null | ||
| -- where id is not null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This model could be removed from the project as it's really just a placeholder for the project. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,2 @@ | ||
|
|
||
| -- Use the `ref` function to select from other models | ||
|
|
||
| select * | ||
| from {{ ref('my_first_dbt_model') }} | ||
| where id = 1 | ||
| select * from {{ ref("my_first_dbt_model") }} where id = 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,39 @@ | ||
|
|
||
| version: 2 | ||
|
|
||
| models: | ||
| - name: my_first_dbt_model | ||
| description: "A starter dbt model" | ||
| columns: | ||
| - name: id | ||
| description: "The primary key for this table" | ||
| tests: | ||
| - unique | ||
| - not_null | ||
| - name: my_first_dbt_model | ||
| description: "A starter dbt model" | ||
| columns: | ||
| - name: id | ||
| description: "The primary key for this table" | ||
| tests: | ||
| - unique | ||
| - not_null | ||
|
|
||
| - name: FName | ||
| description: "The First Name of the Student" | ||
| tests: | ||
| - not_null | ||
|
|
||
| - name: LName | ||
| description: "The Last Name of the Student" | ||
| tests: | ||
| - not_null | ||
|
|
||
| - name: my_second_dbt_model | ||
| description: "A starter dbt model" | ||
| columns: | ||
| - name: id | ||
| description: "The primary key for this table" | ||
| tests: | ||
| - unique | ||
| - not_null | ||
| - name: FName | ||
| description: "The First Name of the Student" | ||
| tests: | ||
| - not_null | ||
|
|
||
| - name: my_second_dbt_model | ||
| description: "A starter dbt model" | ||
| columns: | ||
| - name: id | ||
| description: "The primary key for this table" | ||
| tests: | ||
| - unique | ||
| - not_null | ||
| - name: LName | ||
| description: "The Last Name of the Student" | ||
| tests: | ||
| - not_null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| {{ config(materialized="view") }} | ||
|
|
||
| with | ||
| source_data_view as ( | ||
|
|
||
| select 1 as id, 'Jaggi' as fname, 'Krishna' as lname | ||
| union all | ||
| select 2 as id, 'Todd' as fname, 'Graham' as lname | ||
| union all | ||
| select 3 as id, 'Penny' as fname, 'Davis' as lname | ||
| union all | ||
| select 4 as id, 'John' as fname, 'Kiwa' as lname | ||
| union all | ||
| select null as id, 'Kelly' as fname, 'Greer' as lname | ||
|
|
||
| ) | ||
|
|
||
| select * | ||
| from source_data_view | ||
|
|
||
| /* | ||
| Uncomment the line below to remove records with null `id` values | ||
| */ | ||
| where id is not null |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good, nice use of |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| with orders as ( | ||
| select * from {{ ref ('stg_jaffle_shop__orders' )}} | ||
| ), | ||
|
|
||
| payments as ( | ||
| select * from {{ ref ('stg_stripe__payments') }} | ||
| ), | ||
|
|
||
| order_payments as ( | ||
| select | ||
| order_id, | ||
| sum (case when status = 'success' then amount end) as amount | ||
|
|
||
| from payments | ||
| group by 1 | ||
| ), | ||
|
|
||
|
|
||
| final as ( | ||
|
|
||
| select | ||
| orders.order_id, | ||
| orders.customer_id, | ||
| orders.order_date, | ||
| coalesce (order_payments.amount, 0) as amount | ||
|
|
||
| from orders | ||
| left join order_payments using (order_id) | ||
| ) | ||
|
|
||
| select * from final |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, well formatted, proper use of the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| with customers as ( | ||
|
|
||
| select * from {{ ref('stg_jaffle_shop__customers') }} | ||
|
|
||
| ), | ||
|
|
||
| orders as ( | ||
|
|
||
| select * from {{ ref('stg_jaffle_shop__orders') }} | ||
|
|
||
| ), | ||
|
|
||
| customer_orders as ( | ||
|
|
||
| select | ||
| customer_id, | ||
|
|
||
| min(order_date) as first_order_date, | ||
| max(order_date) as most_recent_order_date, | ||
| count(order_id) as number_of_orders | ||
|
|
||
| from orders | ||
|
|
||
| group by 1 | ||
|
|
||
| ), | ||
|
|
||
| final as ( | ||
|
|
||
| select | ||
| customers.customer_id, | ||
| customers.first_name, | ||
| customers.last_name, | ||
| customer_orders.first_order_date, | ||
| customer_orders.most_recent_order_date, | ||
| coalesce (customer_orders.number_of_orders, 0) | ||
| as number_of_orders | ||
|
|
||
| from customers | ||
|
|
||
| left join customer_orders using (customer_id) | ||
|
|
||
| ) | ||
|
|
||
| select * from final |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {% docs order_status %} | ||
|
|
||
| One of the following values: | ||
|
|
||
| | status | definition | | ||
| |----------------|--------------------------------------------------| | ||
| | placed | Order placed, not yet shipped | | ||
| | shipped | Order has been shipped, not yet been delivered | | ||
| | completed | Order has been received by customers | | ||
| | return pending | Customer indicated they want to return this item | | ||
| | returned | Item has been returned | | ||
|
|
||
| {% enddocs %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| version: 2 | ||
|
|
||
| sources: | ||
| - name: jaffle_shop | ||
| description: A clone of a Postgre application database | ||
| database: raw | ||
| schema: jaffle_shop | ||
| tables: | ||
| - name: customers | ||
| description: This is raw customer data. | ||
| columns: | ||
| - name: id | ||
| description: Customer ID is the primary key | ||
| tests: | ||
| - unique | ||
| - not_null | ||
|
|
||
| - name: orders | ||
| description: This is raw orders data | ||
| columns: | ||
| - name: id | ||
| description: Order ID is the Primary key | ||
| tests: | ||
| - unique | ||
| - not_null |
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.
This looks correct, we want the the project_name to be relevant to the subject area, and we want to build the staging layer as views and the marts layer as tables. Nice work.