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

week 1 project #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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 tables. 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.
6 changes: 6 additions & 0 deletions greenery/macros/lbs_to_kgs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% macro lbs_to_kgs(column_name, precision=2) %}
ROUND(
(CASE WHEN {{ column_name }} = -99 THEN NULL ELSE {{ column_name }} END / 2.205)::NUMERIC,
{{ precision }}
)
{% endmacro %}
9 changes: 9 additions & 0 deletions greenery/macros/positive_values.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% test positive_values(model, column_name) %}


select *
from {{ model }}
where {{ column_name }} < 0


{% endtest %}
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
21 changes: 21 additions & 0 deletions greenery/models/example/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

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_second_dbt_model
description: "A starter dbt model"
columns:
- name: id
description: "The primary key for this table"
tests:
- unique
- not_null
17 changes: 17 additions & 0 deletions greenery/models/staging/postgres/_postgres__models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2

models:
- name: stg_users
description: Contains informaiton about users, such as name, email, phone, address.
- name: stg_addresses
description: Contains information about user addresses.
- name: stg_events
description: Contains information about Webpage event info.
- name: stg_orders
description: Contains information about orders and shipping status.
- name: stg_products
description: Contains information about Greenery's products.
- name: stg_order_items
description: Contains informaion about items ordered.
- name: stg_promos
description: Contains information about promotions.
48 changes: 48 additions & 0 deletions greenery/models/staging/postgres/_postgres__sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 2

sources:

- name: postgres # name of the source (this can be named whatever you want), all the sources are from postgres
schema: public # this is the schema our raw data lives in
database: raw # this is the name of our database

quoting:
database: false
schema: false
identifier: false

freshness:
warn_after: {count: 24, period: hour}
error_after: {count: 48, period: hour}

tables:
- name: addresses
description: >
Contains address information of the users

- name: events
loaded_at_field: created_at
description: >
Contains event information

- name: orders
loaded_at_field: created_at
description: >
Contains order information made on the platform

- name: order_items
description: >
Contains information about the items ordered

- name: products
description: >
Contains information about the platform's products

- name: promos
description: >
Contains infortmation about the platform's promotions

- name: users
loaded_at_field: created_at
description: >
Contains information about the users on the platform
14 changes: 14 additions & 0 deletions greenery/models/staging/postgres/stg_addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='table'
)
}}

SELECT
address_id,
address,
zipcode,
state,
country

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

SELECT
event_id,
session_id,
user_id,
page_url,
created_at,
event_type,
order_id,
product_id

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

SELECT
order_id,
product_id,
quantity

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

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') }}
13 changes: 13 additions & 0 deletions greenery/models/staging/postgres/stg_products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table'
)
}}

SELECT
product_id,
name,
price,
inventory

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

SELECT
promo_id,
discount,
status

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

SELECT
user_id,
first_name,
last_name,
email,
phone_number,
created_at,
updated_at,
address_id


FROM {{ source('postgres', 'users') }}
17 changes: 17 additions & 0 deletions greenery/models/staging/tutorial/_tutorial__models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2

models:
- name: stg_addresses
description: Contains address information of the users.
- name: stg_events
description: Contains event information, such as the type of the event, the page url and the product.
- name: stg_order_items
description: Contains order information made on the platform.
- name: stg_orders
description: Contains information about the items ordered.
- name: stg_products
description: Contains information about the platform's products.
- name: stg_promos
description: Contains infortmation about the platform's promotions.
- name: stg_users
description: Contains information about the users on the platform.
22 changes: 22 additions & 0 deletions greenery/models/staging/tutorial/_tutorial__sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2

sources:

- name: tutorial # name of the source (this can be named whatever you want, but should be descriptive. this source (superheroes) is used for our week 1 tutorial so thats why i named it this way)
schema: public # this is the schema our raw data lives in
database: raw # this is the name of our database

quoting:
database: false
schema: false
identifier: false

freshness:
warn_after: {count: 24, period: hour}
error_after: {count: 48, period: hour}

tables:
- name: superheroes
loaded_at_field: created_at
description: >
Contains demographic information about each superhero
20 changes: 20 additions & 0 deletions greenery/models/staging/tutorial/stg_superheroes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{
config(
materialized='table'
)
}}

SELECT
id AS superhero_id,
name,
gender,
eye_color,
race,
hair_color,
NULLIF(height, -99) AS height,
publisher,
skin_color,
alignment,
NULLIF(weight, -99) AS weight_lbs,
{{ lbs_to_kgs('weight') }} AS weight_kg
FROM {{ source('tutorial', 'superheroes') }}
3 changes: 3 additions & 0 deletions greenery/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- package: dbt-labs/dbt_utils
version: 0.8.2
Empty file added greenery/seeds/.gitkeep
Empty file.
Loading