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

Dimensões criadas #14

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Binary file added Dashboard - Adventure Works.pbix
Binary file not shown.
21 changes: 14 additions & 7 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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: 'my_new_project' # <-- Name of the project.
name: 'dbt_adw' # <-- Name of the project.
version: '1.0.0'
config-version: 2

Expand All @@ -24,22 +24,29 @@ 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:
my_new_project: # <-- Name of the project. If you renamed your project you have to change this as well
dbt_adw: # <-- Name of the project. If you renamed your project you have to change this as well

# Applies to all files under models/example/
example:
materialized: view
staging:
+materialized: view
+schema: staging

marts:
+materialized: table
+schema: marts

intermediate:
+materialized: table
+schema: intermediate

seeds:
my_new_project: # <-- Name of the project. If you renamed your project you have to change this as well
dbt_adw: # <-- Name of the project. If you renamed your project you have to change this as well
sap_adventure_works:
+schema: sap_adw
+schema: sap_adventure_works
1 change: 0 additions & 1 deletion models/example.sql

This file was deleted.

61 changes: 61 additions & 0 deletions models/intermediate.sql/int_salescustomerorders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
with
intermediate_sales_reason as (
select
ID_order as ID_reason_order
,aggregated_sales_reasonsID
,aggregated_reasons
from {{ ref('dim_salesreason') }}
),

intermediate_orders as (
select
pk_orders
,ID_order
,ID_order_detail
,ID_product
,ID_ship_to_address
,ID_credit_card
,ID_customer
,card_type
,order_date
,quantity
,unit_price
,unit_price_discount
,total_due
,freight
,order_status
from {{ ref('dim_orders') }}
),

joined_intermediate as (
select
ID_order
,ID_order_detail
,ID_product
,ID_ship_to_address
,ID_credit_card
,ID_customer
,card_type
,order_date
,quantity
,unit_price
,unit_price_discount
,total_due
,freight
,order_status
,aggregated_reasons
from intermediate_orders
left join intermediate_sales_reason on intermediate_orders.ID_order = intermediate_sales_reason.ID_reason_order

),

primary_key_atribution_transformation as (
select
row_number() over (order by ID_order, ID_order_detail) as ID_sales
, *
from joined_intermediate
)

select *
from primary_key_atribution_transformation
order by ID_sales asc
80 changes: 80 additions & 0 deletions models/intermediate.sql/int_salescustomerorders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: 2
models:
- name: int_salescustomerorders
description: Fact table of the AdvetureWorks erp.
columns:
- name: ID_sales
description: Primary Key of the intemediate salescustomersorders table
tests:
- unique
- not_null

- name: ID_order
description: Primary key. Foreign key to SalesOrderHeader.SalesOrderID.
tests:
- not_null

- name: ID_order_detail
description: Primary key. One incremental unique number per product sold.
tests:
- unique
- not_null

- name: ID_product
description: Product sold to customer. Foreign key to Product.ProductID.
tests:
- not_null

- name: ID_ship_to_address
description: Customer shipping address. Foreign key to Address.AddressID.
tests:
- not_null

- name: ID_credit_card
description: Credit card identification number. Foreign key to CreditCard.CreditCardID.

- name: ID_customer
description: Customer identification number. Foreign key to Customer.BusinessEntityID.
tests:
- not_null

- name: card_type
description: Credit card name.

- name: order_date
description: Dates the sales order was created.
tests:
- not_null

- name: Quantity
description: Quantity ordered per product.
tests:
- not_null

- name: unit_price
description: Selling price of a single product.
tests:
- not_null

- name: unit_price_discount
description: Discount amount.

- name: total_due
description: Total due from customer. Computed as Subtotal + TaxAmt + Freight.
tests:
- not_null

- name: Freight
description: Shipping cost.
tests:
- not_null

- name: order_status
description: Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled
tests:
- not_null

- name: aggregated_reasons
description: Aggregate of all selling reason names that relate to the same order ID


45 changes: 45 additions & 0 deletions models/marts/dim_countryregion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
with
address as (
select
ID_address
,ID_state_province
,city
,postal_code
from {{ ref('stg_address') }}
),

state as (
select
ID_state_province
,ID_territory
,code_state_province
,code_country_region
,state_name
from {{ ref('stg_stateprovince') }}
),

country as (
select
ID_country
,country_name
from {{ ref('stg_countryregion') }}
),

joined_region_data as (
select
ID_address
,address.ID_state_province
,ID_territory
,ID_country
,city
,postal_code
,code_state_province
,state_name
,country_name
from address
left join state on address.ID_state_province = state.ID_state_province
left join country on state.code_country_region = country.ID_country
)

select *
from joined_region_data
51 changes: 51 additions & 0 deletions models/marts/dim_countryregion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 2
models:
- name: dim_countryregion
description: AdventureWorks Countries, States, and Cities dimension table.
columns:

- name: ID_address
description: Primary key for Address records.
tests:
- unique
- not_null

- name: ID_state_province
description: Unique identification number for the state or province. Foreign key to StateProvince table.
tests:
- not_null

- name: ID_territory
description: ID of the territory in which the state or province is located. Foreign key to SalesTerritory.SalesTerritoryID.
tests:
- not_null

- name: ID_country
description: ISO standard code for countries and regions.
tests:
- not_null

- name: City
description: Name of the city.
tests:
- not_null

- name: postal_code
description: Postal code for the street address.
tests:
- not_null

- name: code_state_province
description: ISO standard state or province code.
tests:
- not_null

- name: state_name
description: State or province description.
tests:
- not_null

- name: country_name
description: Country or region name.
tests:
- not_null
34 changes: 34 additions & 0 deletions models/marts/dim_customer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
with
customers as (
select
ID_customer
,ID_person
,ID_store
,ID_territory
from {{ ref('stg_customer') }}
),

persons as (
select
ID_business_entity
,firt_name
,middle_name
,last_name
from {{ ref('stg_person') }}
),

join_customers_to_persons as (
select
ID_customer
,ID_person
,ID_business_entity
,ID_store
,ID_territory
,firt_name || ' ' || last_name as customer_name

from customers
left join persons on customers.ID_person = persons.ID_business_entity
)

select *
from join_customers_to_persons
33 changes: 33 additions & 0 deletions models/marts/dim_customer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2
models:
- name: dim_customer
description: AdventureWorks Customers and People dimension table.
columns:

- name: ID_customer
description: Primary key of dim_customer table.
tests:
- unique
- not_null

- name: ID_person
description: Foreign key to Person.BusinessEntityID.
tests:
- unique

- name: ID_business_entity
description: Primary key for Person records.
tests:
- unique

- name: ID_store
description: Foreign key to Store.BusinessEntityID.

- name: ID_territory
description: ID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID.
tests:
- not_null

- name: customer_name
description: Name of the customer.

Loading