Last active
February 1, 2024 10:03
-
-
Save dltm-markwan/e6945c46aad54766238584bcf937d11d to your computer and use it in GitHub Desktop.
MDS 2023 - Code Starters
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
| {{ | |
| config( | |
| materialized='view' | |
| ) | |
| }} | |
| with final as ( | |
| select | |
| store_id || "-" || cast(id as string) as unique_id, | |
| pk, | |
| id, | |
| store_id, | |
| name, | |
| from {{ source('apjuice', 'users') }} | |
| ) | |
| select | |
| * | |
| from | |
| final |
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
| version: 2 | |
| models: | |
| - name: dim_locations | |
| description: store locations further classified by country | |
| columns: | |
| - name: id | |
| tests: | |
| - not_null | |
| - name: dim_customers | |
| description: Customer details with email addresses | |
| columns: | |
| - name: id | |
| tests: | |
| - not_null | |
| - name: unique_id | |
| tests: | |
| - unique |
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
| {{ | |
| config( | |
| error_if = '>10' | |
| , warn_if = '>0' | |
| ) | |
| }} | |
| select | |
| * | |
| from | |
| {{ ref('top_customers') }} | |
| where | |
| total_spend < 0 |
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
| with sales_items as ( | |
| select * from {{ ref('sales_items') }} | |
| ), | |
| sales as ( | |
| select * from {{ ref('sales') }} | |
| ), | |
| customers as ( | |
| select * from {{ ref('dim_customers') }} | |
| ), | |
| final as ( | |
| select | |
| sales_items.store_id, | |
| sales.unique_customer_id, | |
| customers.name, | |
| sum(product_cost) as total_spend | |
| from | |
| sales_items | |
| join sales on sales_items.sale_id = sales.id | |
| join customers on sales.unique_customer_id = customers.unique_id | |
| where | |
| sales.unique_customer_id is not null | |
| group by sales_items.store_id, sales.unique_customer_id, customers.name | |
| order by total_spend | |
| limit 100 | |
| ) | |
| select | |
| * | |
| from | |
| final |
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
| {% snapshot dim_customers_snapshot %} | |
| {{ | |
| config( | |
| unique_key='unique_id', | |
| strategy='check', | |
| check_cols = 'all' | |
| ) | |
| }} | |
| select * from {{ ref('dim_customers') }} | |
| {% endsnapshot %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment