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 17 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.
13 changes: 7 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,6 +42,10 @@ models:
marts:
+materialized: table
+tags: ['tag']
dims:
+tags: ["myorders"]
facts:
+tags: ["myorders"]
finance:
+group: finance
marketing:
Expand All @@ -65,7 +69,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 %}
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
#}
67 changes: 67 additions & 0 deletions models/intermediate/cfo/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

36 changes: 36 additions & 0 deletions models/intermediate/orders/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
36 changes: 36 additions & 0 deletions models/marts/dims/_dims__data_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2

models:
- name: dim_orders
config:
contract:
enforced: true
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)

- name: dim_countries
columns:
- name: country_name
data_tests:
- accepted_values:
values:
- "United States"
- "France"
- "Italy"
- "Philippines"
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": "0"}

- 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
16 changes: 16 additions & 0 deletions models/marts/dims/cfo/dim_depreciation_accounts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ config(
materialized='table',
tags=["cfo"]
) }}


with

source as (

select '1'::numeric(10, 3) as account_id, '-1000.00'::numeric(10, 3) depreciation_cost_usd,'Major'::varchar as account_type, '2024-01-01'::date as record_updated_ts union all
select '2'::numeric(10, 3) as account_id, '-1000.00'::numeric(10, 3) depreciation_cost_usd,'Minor'::varchar as account_type, '2024-01-01'::date as record_updated_ts

)

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


with

source as (

select '1'::numeric(10, 3) as account_id, '10000.00'::numeric(10, 3) interests_amount_usd,'Major'::varchar as account_type, '2024-01-01'::date as record_updated_ts union all
select '2'::numeric(10, 3) as account_id, '10000.00'::numeric(10, 3) interests_amount_usd,'Minor'::varchar as account_type, '2024-01-01'::date as record_updated_ts

)

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


with

source as (

select '1'::numeric(10, 3) as account_id, '10000.00'::numeric(10, 3) net_income_usd,'Major'::varchar as account_type, '2024-01-01'::date as record_updated_ts union all
select '2'::numeric(10, 3) as account_id, '10000.00'::numeric(10, 3) net_income_usd,'Minor'::varchar as account_type, '2024-01-01'::date as record_updated_ts

)

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

with

source as (

select '1'::numeric(10, 3) as account_id, '-2000.00'::numeric(10, 3) tax_usd,'Major'::varchar as account_type, '2024-01-01'::date as record_updated_ts union all
select '2'::numeric(10, 3) as account_id, '-2000.00'::numeric(10, 3) tax_usd,'Minor'::varchar as account_type, '2024-01-01'::date as record_updated_ts

)

select * from source
Loading