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

🚑 Fix incremental logic to accommodate for window functions #4

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions models/core/_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ models:
description: 'The unique order ID for the transaction.'
tests:
- not_null
- unique:
where: "valid_to is null"

- name: takehome_percentage
data_type: varchar
Expand Down
22 changes: 18 additions & 4 deletions models/core/revenuecat_subscription_transactions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@
config(
materialized = 'incremental',
unique_key = 'transaction_row_id',
merge_update_columns = ['valid_to'],
)
}}

with
with
{% if is_incremental() %}
merge_identifiers as (
select distinct store_transaction_id
from {{ source('revenuecat', 'transactions') }}
where regexp_substr(_file_name, '[0-9]{10}')::timestamp_ntz > (
select max(_exported_at)
from {{ this }}
)
),
{% endif %}

source as (
select
*
from
{{ source('revenuecat', 'transactions') }}
{{ source('revenuecat', 'transactions') }} src
jurrigerretsen marked this conversation as resolved.
Show resolved Hide resolved

where 1=1
{% if var('revenuecat_filter') %}
and {{ var('revenuecat_filter') }}
{% endif %}
{% if is_incremental() %}
and regexp_substr(_file_name, '[0-9]{10}')::timestamp_ntz > (select max(_exported_at) from {{ this }})
{% if is_incremental() %}
and store_transaction_id in (
select store_transaction_id
from merge_identifiers
)
{% endif %}

),
Expand Down
Loading