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

update stripe package with running total model #60

Merged
merged 10 commits into from
Mar 21, 2023
Merged
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

# dbt_stripe v0.10.0
[#60](https://github.com/fivetran/dbt_stripe/pull/60) includes the following changes:
## 🚨 Breaking Changes 🚨:
- Unwrapped `total_*` fields from the for loop in `stripe__daily_overview` to reduce compute required for previous for-loops
- Add `account_id` in `int_stripe__account_rolling_totals` for use as part of the join in the case where more than 1 `account_id` exists.

## Under the Hood
- Intermediate model materializations have changed from ephemeral to table to reduce the compute required for the complexity of calculations.

# dbt_stripe v0.9.0

[#56](https://github.com/fivetran/dbt_stripe/pull/56) includes the following changes:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Include the following stripe package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/stripe
version: [">=0.9.0", "<0.10.0"]
version: [">=0.10.0", "<0.11.0"]

```
## Step 3: Define database and schema variables
Expand Down
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
config-version: 2
name: 'stripe'

version: '0.9.0'
version: '0.10.0'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
stripe:
+schema: stripe
+materialized: table
intermediate:
+materialized: ephemeral
+materialized: table
vars:
stripe:
account: "{{ ref('stg_stripe__account') }}"
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'stripe_integration_tests'
version: '0.9.0'
version: '0.10.0'

profile: 'integration_tests'

Expand Down
1 change: 0 additions & 1 deletion models/intermediate/int_stripe__account_partitions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ with account_rolling_totals as (
from {{ ref('int_stripe__account_rolling_totals') }}
),


final as (

select
Expand Down
2 changes: 2 additions & 0 deletions models/intermediate/int_stripe__account_rolling_totals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with date_spine as (
), final as (

select
date_spine.account_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this added to help with the join? I would add the reason for this addition to the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, added!

date_spine.date_day,
date_spine.date_week,
date_spine.date_month,
Expand All @@ -46,6 +47,7 @@ with date_spine as (
from date_spine
left join account_rolling_totals
on account_rolling_totals.date_day = date_spine.date_day
and account_rolling_totals.account_id = date_spine.account_id
and account_rolling_totals.source_relation = date_spine.source_relation
)

Expand Down
18 changes: 18 additions & 0 deletions models/stripe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: 2

models:
- name: int_stripe__account_daily
description: Each record represents each day's ending balances per account.

- name: int_stripe__account_partitions
description: Each record is a group of partitioned account totals updating null values with zeroes to eventually calculate running totals downstream.

- name: int_stripe__account_rolling_totals
description: Each record represents each day's ending balances per account, in addition to changes over time.

- name: int_stripe__date_spine
description: Each record represents a day of each calendar year.

- name: int_stripe__incomplete_charges
description: Each record represents a charge that is incomplete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was helpful to understand what the different int models do!

- name: stripe__balance_transactions
description: Each record represents a change to your account balance, enriched with data about the transaction.
tests:
Expand Down Expand Up @@ -387,9 +402,12 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- account_id
- date_day
- source_relation
columns:
- name: account_id
description: The ID of the account tied to the balance.
- name: date_day
description: Day of record, taken from the date of each balance transaction.
- name: source_relation
Expand Down
42 changes: 28 additions & 14 deletions models/stripe__daily_overview.sql
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
{% set total_fields = ['total_daily_sales_amount', 'total_daily_refunds_amount', 'total_daily_adjustments_amount', 'total_daily_other_transactions_amount', 'total_daily_gross_transaction_amount', 'total_daily_net_transactions_amount', 'total_daily_payout_fee_amount', 'total_daily_gross_payout_amount', 'daily_net_activity_amount', 'daily_end_balance_amount', 'total_daily_sales_count', 'total_daily_payouts_count', 'total_daily_adjustments_count', 'total_daily_failed_charge_count', 'total_daily_failed_charge_amount'] %}
{% set rolling_fields = ['rolling_total_daily_sales_amount', 'rolling_total_daily_refunds_amount', 'rolling_total_daily_adjustments_amount', 'rolling_total_daily_other_transactions_amount', 'rolling_total_daily_gross_transaction_amount', 'rolling_total_daily_net_transactions_amount', 'rolling_total_daily_payout_fee_amount', 'rolling_total_daily_gross_payout_amount', 'rolling_daily_net_activity_amount', 'rolling_daily_end_balance_amount', 'rolling_total_daily_sales_count', 'rolling_total_daily_payouts_count', 'rolling_total_daily_adjustments_count', 'rolling_total_daily_failed_charge_count', 'rolling_total_daily_failed_charge_amount'] %}

with account_partitions as (

select *
from {{ ref('int_stripe__account_partitions') }}
),

), final as (
final as (

select
date_day,
date_week,
date_month,
date_year,

{% for t in total_fields %}
{{ t }},
{% endfor %}
account_id,
{{ dbt_utils.generate_surrogate_key(['account_id','date_day']) }} as account_daily_id,
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't catch this before, but I'm getting a test failure from

    combination_of_columns:
            - date_day
            - source_relation

Guessing this test needs to be adjusted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, added account_id, forgot I included that field now. Should be good now, thanks for catching!


date_day,
date_week,
date_month,
date_year,
date_index,
source_relation,
coalesce(total_daily_sales_amount,0) as total_daily_sales_amount,
coalesce(total_daily_refunds_amount,0) as total_daily_refunds_amount,
coalesce(total_daily_adjustments_amount,0) as total_daily_adjustments_amount,
coalesce(total_daily_other_transactions_amount,0) as total_daily_other_transactions_amount,
coalesce(total_daily_gross_transaction_amount,0) as total_daily_gross_transaction_amount,
coalesce(total_daily_net_transactions_amount,0) as total_daily_net_transactions_amount,
coalesce(total_daily_payout_fee_amount,0) as total_daily_payout_fee_amount,
coalesce(total_daily_gross_payout_amount,0) as total_daily_gross_payout_amount,
coalesce(daily_net_activity_amount,0) as daily_net_activity_amount,
coalesce(daily_end_balance_amount,0) as daily_end_balance_amount,
coalesce(total_daily_sales_count,0) as total_daily_sales_count,
coalesce(total_daily_payouts_count,0) as total_daily_payouts_count,
coalesce(total_daily_adjustments_count,0) as total_daily_adjustments_count,
coalesce(total_daily_failed_charge_count,0) as total_daily_failed_charge_count,
coalesce(total_daily_failed_charge_amount,0) as total_daily_failed_charge_amount,
{% for f in rolling_fields %}
coalesce({{ f }},
first_value({{ f }}) over (partition by {{ f }}_partition order by date_day rows unbounded preceding)) as {{ f }},
first_value({{ f }}) over (partition by {{ f }}_partition order by date_day rows unbounded preceding)) as {{ f }}
{%- if not loop.last -%},{%- endif -%}
{% endfor %}

source_relation

from account_partitions
)
)

select *
from final