Skip to content

Commit

Permalink
initial commit with prework code
Browse files Browse the repository at this point in the history
  • Loading branch information
coapacetic committed Jan 10, 2022
0 parents commit d4db274
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_modules/
logs/
15 changes: 15 additions & 0 deletions 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](http://slack.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
37 changes: 37 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'jaffle_shop'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'default'

# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
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_modules"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the jaffle_shop project
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.

models:
jaffle_shop:
+materialized: table
45 changes: 45 additions & 0 deletions models/customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
with customers as (

select * from {{ ref('stg_customers') }}

),

orders as (

select * from {{ ref('stg_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
33 changes: 33 additions & 0 deletions models/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2

models:
- name: customers
columns:
- name: customer_id
tests:
- unique
- not_null

- name: stg_customers
columns:
- name: customer_id
tests:
- unique
- not_null

- name: stg_orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']
- name: customer_id
tests:
- not_null
- relationships:
to: ref('stg_customers')
field: customer_id
6 changes: 6 additions & 0 deletions models/stg_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
id as customer_id,
first_name,
last_name

from `dbt-tutorial`.jaffle_shop.customers
7 changes: 7 additions & 0 deletions models/stg_orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
id as order_id,
user_id as customer_id,
order_date,
status

from `dbt-tutorial`.jaffle_shop.orders

0 comments on commit d4db274

Please sign in to comment.