Skip to content
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

Project1 #70

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
setting up models
(cherry picked from commit 2bc9242)
  • Loading branch information
dguillamot committed Apr 14, 2023
commit fd25901d9c6e5a305c3d2c820546110df1e5b676
4 changes: 4 additions & 0 deletions greenery/.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 greenery/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 added greenery/analyses/.gitkeep
Empty file.
38 changes: 38 additions & 0 deletions greenery/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# 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: 'greenery'
version: '1.0.0'
config-version: 2

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

# These configurations specify where dbt should look for different types of files.
# The `model-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!
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

# In this example config, we tell dbt to build all models in the example/
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
greenery:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: view
Empty file added greenery/macros/.gitkeep
Empty file.
27 changes: 27 additions & 0 deletions greenery/models/example/my_first_dbt_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/*
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') }}

with source_data as (

select 1 as id
union all
select null as id

)

select *
from source_data

/*
Uncomment the line below to remove records with null `id` values
*/

-- where id is not null
6 changes: 6 additions & 0 deletions greenery/models/example/my_second_dbt_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

-- Use the `ref` function to select from other models

select *
from {{ ref('my_first_dbt_model') }}
where id = 1
20 changes: 20 additions & 0 deletions greenery/models/example/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

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

- name: my_second_dbt_model
description: "A starter dbt model"
columns:
- name: id
description: "The primary key for this table"
tests:
- unique
- not_null
19 changes: 19 additions & 0 deletions greenery/models/staging/postgres/src_postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2

sources:
- name: postgres
database: raw
schema: public
tables:
- name: addresses
- name: events
- name: orders
- name: order_items
- name: products
- name: promos
- name: users





23 changes: 23 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{
config(materialized = 'table')
}}

with source as (
select address_id
, address
, state
, zipcode
, country from {{ source('postgres', 'addresses') }}
)

, renamed_recast as (
select
address_id as address_guid
, address
, state
, lpad(zipcode, 5, 0) as zip_code
, country
from source
)

select * from renamed_recast
29 changes: 29 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{
config(materialized = 'table')
}}

with source as (
select event_id
, session_id
, user_id
, page_url
, created_at
, event_type
, order_id
, product_id from {{ source('postgres', 'events') }}
)

, renamed_recast as (
select
event_id as event_guid
, session_id as session_guid
, user_id as user_guid
, page_url
, created_at
, event_type
, order_id as order_guid
, product_id as product_guid
from source
)

select * from renamed_recast
19 changes: 19 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__order_items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(materialized = 'table')
}}

with source as (
select order_id
, product_id
, quantity from {{ source('postgres', 'order_items') }}
)

, renamed_recast as (
select
order_id as order_guid
, product_id as product_guid
, quantity
from source
)

select * from renamed_recast
39 changes: 39 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{
config(materialized = 'table')
}}

with source as (
select order_id
, user_id
, promo_id
, address_id
, created_at
, order_cost
, shipping_cost
, order_total
, tracking_id
, shipping_service
, estimated_delivery_at
, delivered_at
, status from {{ source('postgres', 'orders') }}
)

, renamed_recast as (
select
order_id as order_guid
, user_id as user_guid
, promo_id as promo_guid
, address_id as address_guid
, created_at
, order_cost
, shipping_cost
, order_total
, tracking_id as tracking_guid
, shipping_service
, estimated_delivery_at
, delivered_at
, status
from source
)

select * from renamed_recast
21 changes: 21 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{
config(materialized = 'table')
}}

with source as (
select product_id
, name
, price
, inventory from {{ source('postgres', 'products') }}
)

, renamed_recast as (
select
product_id as product_guid
, name
, price
, inventory
from source
)

select * from renamed_recast
19 changes: 19 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__promos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(materialized = 'table')
}}

with source as (
select promo_id
, discount
, status from {{ source('postgres', 'promos') }}
)

, renamed_recast as (
select
promo_id as promo_guid
, discount
, status
from source
)

select * from renamed_recast
29 changes: 29 additions & 0 deletions greenery/models/staging/postgres/stg_postgres__users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{
config(materialized = 'table')
}}

with source as (
select user_id
, first_name
, last_name
, email
, phone_number
, created_at
, updated_at
, address_id from {{ source('postgres', 'users') }}
)

, renamed_recast as (
select
user_id as user_guid
, first_name
, last_name
, email
, phone_number
, created_at
, updated_at
, address_id as address_guid
from source
)

select * from renamed_recast
Empty file added greenery/seeds/.gitkeep
Empty file.
Empty file added greenery/snapshots/.gitkeep
Empty file.
Empty file added greenery/tests/.gitkeep
Empty file.