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

Anything with commit changes #107

Open
wants to merge 19 commits into
base: qa
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
Empty file added analysis/test_file.sql
Empty file.
20 changes: 14 additions & 6 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ vars:
incremental_lookback_period: 'hour'
future_proof_date: '9999-12-31'

on-run-end:
- "{% if target.name == 'prod' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"
# on-run-end:
# - "{% if target.name == 'prod' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"


# Configuring models
Expand All @@ -42,12 +42,23 @@ models:
marts:
+materialized: table
+tags: ['tag']
dims:
+tags: ["myorders"]
facts:
+tags: ["myorders"]
finance:
+group: finance
marketing:
+group: marketing
operations:
+group: operations
accounting:
+group: accounting
+access: public
cfo:
+group: cfo
+access: public

intermediate:
+materialized: view
staging:
Expand All @@ -65,7 +76,4 @@ models:
+materialized: ephemeral

tests:
rapid_onboarding_exemplar:
_samples:
staging:
+store_failures: "{{ true if target.name == 'prod' else false }}"
+store_failures: false
5 changes: 5 additions & 0 deletions macros/test_macro.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro test_macro() %}

{{ log("This is a message by log macro", info=True) }}

{% endmacro %}
10 changes: 10 additions & 0 deletions models/_groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
groups:
- name: cfo
owner:
# 'name' or 'email' is required; additional properties allowed
email: cfo@mycompany.com

- name: accounting
owner:
email: finance@mycompany.com

1 change: 1 addition & 0 deletions models/_samples/incremental/example_incremental_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

with source as (
select * from {{ ref('example_source_for_incremental') }}

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
where _etl_loaded_at > (select max(_etl_loaded_at) from {{ this }})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with order_snapshot as (
{# with order_snapshot as (
select
* exclude dbt_valid_to,
coalesce(dbt_valid_to, cast('{{ var("future_proof_date") }}' as timestamp)) as dbt_valid_to
Expand Down Expand Up @@ -47,3 +47,4 @@ final as (
)

select * from final
#}
36 changes: 36 additions & 0 deletions models/intermediate/finance/int_daily_orders_fact.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
with

dates as (

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

),

orders as (

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

),

countries as (

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

),

join_sources as (

select
ordr.order_sk,
country.country_sk as order_country_origin_sk,
date.date_sk as order_date_sk,
ordr.order_quantity
from orders ordr
left join dates date
on ordr.order_date = date.calendar_date
left join countries country
on ordr.order_country_origin = country.country_name

)

select * from join_sources
67 changes: 67 additions & 0 deletions models/marts/accounting/int_revenue_fct.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{ config(
materialized='table',
tags=["cfo"]
) }}

with

depreciations as (

select * from {{ ref('dim_depreciation_accounts') }}
where account_type = 'Major'

),

interests as (

select * from {{ ref('dim_interests_accounts') }}
where account_type = 'Major'

),

net_income as (

select * from {{ ref('dim_net_income') }}
where account_type = 'Major'

),


taxes as (

select * from {{ ref('dim_tax_accounts') }}
where account_type = 'Major'

),

join_sources as (

select
net_inc.account_id,
net_inc.net_income_usd,
deprec.depreciation_cost_usd,
ints.interests_amount_usd,
tax.tax_usd,
net_inc.account_type
from net_income net_inc
left join depreciations deprec
on net_inc.account_id = deprec.account_id
left join interests ints
on net_inc.account_id = ints.account_id
left join taxes tax
on net_inc.account_id = tax.account_id

),

final as (

select
account_id,
account_type,
(net_income_usd + interests_amount_usd + tax_usd + depreciation_cost_usd)::numeric(10, 3) as ebitda
from join_sources

)

select * from final

14 changes: 14 additions & 0 deletions models/marts/cfo/fct_revenue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ config(
materialized='table',
tags=["cfo"]
) }}

with

sources as (

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

)

select * from sources
119 changes: 119 additions & 0 deletions models/marts/dims/_dims__unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
version: 2

unit_tests:
- name: test_if_full_name_format_is_correct
description: "Checks if the format for customer full name is correct"
model: dim_customer_info
config:
tags: |
{%- if target.name == 'prod' -%} unit_test
{%- else -%} do_not_run
{% endif %}
given:
- input: ref('dim_orders')
rows:
- {"cust_fname": "Johnny", "cust_lname": "Bravo"}

expect:
rows:
- {cust_fullname: "Bravo, Johnny"}

- name: test_accuracy_of_ebitda_calculation
description: "Test if the EBITDA calculation is correct"
model: int_revenue_fct
config:
tags: |
{%- if target.name != 'prod' -%} unit_test
{%- else -%} do_not_run
{% endif %}

given:
- input: ref('dim_depreciation_accounts')
rows:
- {"account_id": "1", "account_type": "Major", "depreciation_cost_usd": "-10"}

- input: ref('dim_interests_accounts')
rows:
- {"account_id": "1", "account_type": "Major", "interests_amount_usd": "10"}

- input: ref('dim_net_income')
rows:
- {"account_id": "1", "account_type": "Major", "net_income_usd": "10"}

- input: ref('dim_tax_accounts')
rows:
- {"account_id": "1", "account_type": "Major", "tax_usd": "-10"}

expect:
rows:
- {"account_id": "1", "account_type": "Major", "ebitda": "-1"}

- name: test_accuracy_of_ebitda_calculation__sql_format
description: "Test if the EBITDA calculation is correct using SQL format"
model: int_revenue_fct
config:
tags: |
{%- if target.name != 'prod' -%} unit_test
{%- else -%} do_not_run
{% endif %}

given:
- input: ref('dim_depreciation_accounts')
format: sql
rows: |
with
main as (
select
'1'::numeric(10, 3) as account_id,
'Major'::varchar as account_type,
'-10'::numeric(10, 3) as depreciation_cost_usd
)

select * from main

- input: ref('dim_interests_accounts')
format: sql
rows: |
with
main as (
select
'1'::numeric(10, 3) as account_id,
'Major'::varchar as account_type,
'10'::numeric(10, 3) as interests_amount_usd
)

select * from main

- input: ref('dim_net_income')
format: sql
rows: |
with
main as (
select
'1'::numeric(10, 3) as account_id,
'Major'::varchar as account_type,
'10'::numeric(10, 3) as net_income_usd
)

select * from main

- input: ref('dim_tax_accounts')
format: sql
rows: |
with
main as (
select
'1'::numeric(10, 3) as account_id,
'Major'::varchar as account_type,
'-10'::numeric(10, 3) as tax_usd
)

select * from main

expect:
format: sql
rows: |
select
1::numeric(10, 3) as account_id,
'Major' as account_type,
0::numeric(10, 3) as ebitda
65 changes: 65 additions & 0 deletions models/marts/dims/_properties.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: 2



models:
- name: dim_orders
latest_version: 2

versions:
- v: 1
config:
columns:
- name: order_sk
data_type: decimal(10,2)
data_tests:
- unique
- not_null
- name: cust_fname
data_type: string
- name: cust_lname
data_type: string
- name: order_country_origin
data_type: string
- name: order_date
data_type: date
- name: order_id
data_type: string
- name: order_quantity
data_type: decimal(15,2)

- v: 2
config:
alias: dim_orders
#group: accounting
columns:
- name: order_sk
data_type: decimal(10,2)
data_tests:
- unique
- not_null
- name: credit_card_number
data_type: varchar(100)
- name: cust_fname
data_type: string
- name: cust_lname
data_type: string
- name: order_country_origin
data_type: string
- name: order_date
data_type: date
- name:
data_type: string

- name: dim_countries
config:
group: accounting
columns:
- name: country_name
data_tests:
- accepted_values:
values:
- "United States"
- "France"
- "Italy"
- "Philippines"
Loading
Loading