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

dbt Tesst #29

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
44d251c
Configuração do DW. Conexão com o Snowflake
Jan 9, 2025
171a68a
Creation of the sources.yml file
dianadias1 Jan 12, 2025
b6f081d
Sources atualization
dianadias1 Jan 14, 2025
b5503a2
Updating configs and README
dianadias1 Jan 14, 2025
8e3f6ef
Staging models creation
dianadias1 Jan 14, 2025
244391f
Updating stagins
dianadias1 Jan 16, 2025
00eafef
Updating configs
dianadias1 Jan 16, 2025
af7a978
dim_dates criation
dianadias1 Jan 16, 2025
03f6cc7
Updating staging
dianadias1 Jan 16, 2025
3479d85
dim_products criation
dianadias1 Jan 16, 2025
eef48a3
dim_customers criation
dianadias1 Jan 16, 2025
582e801
dim_region criation
dianadias1 Jan 16, 2025
4a0f44d
dim_sales_person criation
dianadias1 Jan 16, 2025
9d743e0
dim_sales_reason criation
dianadias1 Jan 16, 2025
ea5179c
dim_special_offer criation and updating stg_specialoffer and stg_spec…
dianadias1 Jan 16, 2025
8c54226
Updating dim_customers and stg_customer
dianadias1 Jan 17, 2025
9aaa307
Updating dim_customers and stg_customer
dianadias1 Jan 17, 2025
fc3bb74
Updating dim_region
dianadias1 Jan 17, 2025
329eae4
Updating dim_sales_person
dianadias1 Jan 17, 2025
c026c37
Updating dim_sales_reason
dianadias1 Jan 17, 2025
c8a84bb
Criation of dim_customers.yml
dianadias1 Jan 17, 2025
090fa08
Updating of dim_customers.yml
dianadias1 Jan 17, 2025
22fe49c
Criation of dim_products.yml
dianadias1 Jan 17, 2025
4bbbdbb
Updating dim_customers
dianadias1 Jan 17, 2025
3d16b8e
Criatio of the dim_region.ymln
dianadias1 Jan 17, 2025
299dcda
Criation of the dim_sales_person.yml
dianadias1 Jan 17, 2025
76c1dc8
Criation of the dim_sales_reason and updating of the sources.yml
dianadias1 Jan 17, 2025
46a83c2
Criation of the dim_sales_reason.yml
dianadias1 Jan 17, 2025
3218062
Criation of the dim_special_offer.yml and updating dim_special_offer.…
dianadias1 Jan 17, 2025
506cf34
dim_ship_method creation and dependencies update
dianadias1 Jan 17, 2025
5ab6d63
dim tables update
dianadias1 Jan 17, 2025
71eb1a0
dim tables Update
dianadias1 Jan 17, 2025
34b1762
Updating dim_special_offer
dianadias1 Jan 17, 2025
5bea153
Fct_order-details creation and documentation
dianadias1 Jan 18, 2025
405a823
dim_dates update
dianadias1 Jan 18, 2025
a2f95bc
soucer.yml update
dianadias1 Jan 18, 2025
990caf2
dim_dates.yml creation
dianadias1 Jan 18, 2025
cabed85
fct_order_details update
dianadias1 Jan 18, 2025
c875f2a
dim_sales_person update
dianadias1 Jan 18, 2025
97f10b9
agg_sales creation
dianadias1 Jan 18, 2025
2b30174
Creation of the agg_sales documentation and update of dependencies
dianadias1 Jan 18, 2025
20cee9d
Update of documentation and tests
dianadias1 Jan 18, 2025
279ad2b
Configuration of the materialization type of the models
dianadias1 Jan 18, 2025
95154b8
dim_ship_method.yml update
dianadias1 Jan 18, 2025
424850b
Data test for orders quantity
dianadias1 Jan 18, 2025
6fa4154
Deduping fct_order_details
dianadias1 Jan 19, 2025
b27a21d
Agg_sales update
dianadias1 Jan 20, 2025
182ce72
dim_customers update
dianadias1 Jan 20, 2025
644aeed
dim_region debug
dianadias1 Jan 21, 2025
70ac92a
Stg_customer correction
dianadias1 Jan 21, 2025
642386e
dim_region update
dianadias1 Jan 22, 2025
42717ea
agg_sales update
dianadias1 Jan 22, 2025
c2041ee
agg_sales_by_store creation
dianadias1 Jan 22, 2025
2418793
Update agg_sales_by_store
dianadias1 Jan 24, 2025
b330703
Add schema prod
dianadias1 Jan 24, 2025
581cbdd
readme update
dianadias1 Jan 26, 2025
5510694
Requirements
dianadias1 Jan 26, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
target/
dbt_packages/
logs/

venv
1 change: 1 addition & 0 deletions .user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id: d2acdfe4-0365-48cc-a665-d08289354915
61 changes: 57 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
# Indicium Academy
# Desafio Final LightHouse

# Adventure Works dbt

## Estrutura do Projeto

- models/: Contém todos os modelos dbt.
- staging/: Modelos de staging que preparam dados brutos para uso posterior.
- marts/: Modelos de marts que agregam e transformam dados para análise.
- tests/: Contém testes para garantir a qualidade dos dados.
- macros/: Contém macros reutilizáveis para o projeto.

## Configurações de ambiente

### Ativando o virtual environment

O virtual environment deve ser ativado a cada novo dia através do comando em bash no Windows:

- `source venv/Scripts/activate`

Para desativar o ambiente virtual, basta rodar:

- `deactivate`.

### Comandos do dbt

Para confirmar se o **profiles.yml** e o **dbt_project.yml** estão configurados e rodando corretamente, além de verificar novamente as dependências e as conexões necessárias:

- `dbt debug`

Para instalar os pacotes descritos no arquivo *packages.yml*, pode-se rodar:

- `dbt deps`

Para fazer testes nas sources:

- `dbt test --select "source:*"`

Para refazer os modelos e atualizar os metadados:

- `dbt run -s <modelo> --full-refresh`

### Comandos de git

Remover um arquivo caso eu tenha dado git add nele mas não quero commitar ele.

- `git reset <nome_do_arquivo>`




# Readme do repositório clonado

## Indicium Academy

Repositório para ser utilizado no desafio para a obtenção da certificação de Analytics Engineer by Indicium. Faça o fork deste repositório e o utilize durante o desafio para fazer a insgestão das tabelas do SAP do Adventure Works.

## Instruções
### Instruções

Todas as tabelas do banco fonte do SAP da Adventure Works serão carregadas como seeds pelo dbt. Os arquivos .csv com os dados já estão na pasta de seeds.

Expand All @@ -12,12 +65,12 @@ Para fazer o carregamento de todas as tabelas usem o comando:
Para carregar uma tabela especifíca utilizem o comando
- `dbt seed -s nome_do_csv`

### Problemas comuns
#### Problemas comuns

Em caso a linha de comando do dbt fique com o status de estar sempre carregando, ou, o job do comando `dbt seed` fique rodando indefinitivamente mesmo após as 64 tabelas forem carregadas você precisará reiniciar o terminal. Para isso, clique nos três pontos no canto inferior direito ou no lado direito da linha de comando e escolha a opção `Restart IDE`.


## Recursos:
### Recursos:
- 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 [dbt community](http://community.getbdt.com/) to learn from other analytics engineers
Expand Down
19 changes: 12 additions & 7 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# 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: 'adventureworks_dbt' # <-- Name of the project.
version: '1.0.0'
config-version: 2

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

# 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
Expand All @@ -32,14 +32,19 @@ clean-targets: # directories to be removed by `dbt clean`
# 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

adventureworks_dbt: # <-- Name of the project. If you renamed your project you have to change this as well
+persist_docs:
relation: true
columns: true
# Applies to all files under models/example/
example:
materialized: view
staging:
+materialized: view
marts:
+schema: prod
+materialized: table


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

This file was deleted.

57 changes: 57 additions & 0 deletions models/marts/agg_sales.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* This table is a aggregation of sales by sales person and sales terrytory */
with
fct_order_details as (
select
*
from {{ ref('fct_order_details') }}
)

, dim_region as (
select
*
from {{ ref('dim_region') }}
)

, dim_sales_person as (
select
*
from {{ ref('dim_sales_person') }}
)

, final_agg as (
select
{{ dbt_utils.generate_surrogate_key([
"dim_region.territory_id"
, "dim_region.stateprovince_id"
, "dim_region.country_region_name"
, "fct_order_details.salesorder_id"
]) }} as aggsales_sk
, dim_region.region_sk as region_fk
, dim_sales_person.salesperson_sk as salesperson_fk
, fct_order_details.orderdetail_sk as orderdetail_fk
, dim_sales_person.businessentity_id
, dim_region.geographical_region
, dim_region.territory_name
, dim_region.country_region_name
, dim_region.state_province_name
, dim_region.territory_sales_ytd
, dim_region.territory_sales_last_year
, dim_region.territory_cost_ytd
, dim_region.territory_cost_last_year
, dim_sales_person.person_name
, fct_order_details.payment_method
, fct_order_details.subtotal
, fct_order_details.total_due
, fct_order_details.orderqty
, fct_order_details.unitprice
, fct_order_details.unitprice_discount
, fct_order_details.order_date
from fct_order_details
left join dim_region
on fct_order_details.region_fk = dim_region.region_sk
left join dim_sales_person
on fct_order_details.salesperson_fk = dim_sales_person.salesperson_sk
)

select *
from final_agg
89 changes: 89 additions & 0 deletions models/marts/agg_sales.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
version: 2

models:
- name: agg_sales
description: Aggregates sales information by salesperson and region
columns:
- name: aggsales_sk
description: The Primary Key of table.
tests:
- not_null
- unique

- name: region_fk
description: Foreign Key for the region.
tests:
- not_null
- relationships:
to: ref('dim_region')
field: region_sk

- name: salesperson_fk
description: Foreign Key for the sales person.
tests:
- relationships:
to: ref('dim_sales_person')
field: salesperson_sk

- name: orderdetail_fk
description: Foreign Key for the order details.
tests:
- relationships:
to: ref('fct_order_details')
field: orderdetail_sk

- name: businessentity_id
description: Natural Key for the sales person.

- name: geographical_region
description: Name of geographical region.

- name: territory_name
description: Name of the territory.

- name: country_region_name
description: Name of the country or region.

- name: state_province_name
description: Name of the state or province.

- name: territory_sales_ytd
description: Year-to-date sales total.

- name: territory_sales_last_year
description: Last year sales total.

- name: territory_cost_ytd
description: Year-to-date cost total.

- name: territory_cost_last_year
description: Last year cost total.

- name: person_name
description: Person's name.

- name: payment_method
description: Payment method.

- name: subtotal
description: Total value of items before tax and freight.

- name: total_due
description: Total amount due for the order.

- name: orderqty
description: Quantity of the product sold.

- name: unitprice
description: Unit price of the product.

- name: unitprice_discount
description: Discount applied per unit.

- name: order_date
description: Date for the sales order.
tests:
- relationships:
to: ref('dim_dates')
field: date_day

59 changes: 59 additions & 0 deletions models/marts/agg_sales_by_store.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* This table is a aggregation of sales by sales person and sales terrytory */
with
fct_order_details as (
select
*
from {{ ref('fct_order_details') }}
)

, dim_region as (
select
*
from {{ ref('dim_region') }}
)

, dim_customers as (
select
*
from {{ ref('dim_customers') }}
)

, dim_products as (
select
*
from {{ ref('dim_products') }}
)

, final_agg as (
select
fct_order_details.salesorder_id
, dim_customers.store_id
, dim_products.product_id
, dim_region.territory_id
, dim_region.stateprovince_id
, dim_customers.store_name
, dim_region.geographical_region
, dim_region.country_region_name
, dim_region.territory_name
, dim_region.state_province_name
, dim_region.isonlystateprovinceflag
, fct_order_details.total_due
, fct_order_details.orderqty
, fct_order_details.unitprice
, dim_products.product_name
, dim_products.subcategory_name
, dim_products.category_name
, dim_products.total_quantity
, fct_order_details.order_date
from fct_order_details
left join dim_region
on fct_order_details.region_fk = dim_region.region_sk
left join dim_customers
on fct_order_details.customers_fk = dim_customers.customers_sk
left join dim_products
on fct_order_details.products_fk = dim_products.products_sk
)

select *
from final_agg
where store_id is not null
Loading