From 18cefca40e40f853312926a53b6b7dcc17e5eddd Mon Sep 17 00:00:00 2001 From: Jurri Gerretsen <62351599+jurrigerretsen@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:49:08 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9A=91=20Fix=20incremental=20logic=20?= =?UTF-8?q?to=20accommodate=20for=20window=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/core/_core.yml | 2 ++ models/core/revenuecat_subscription_transactions.sql | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/models/core/_core.yml b/models/core/_core.yml index f8b2d56..c546c98 100644 --- a/models/core/_core.yml +++ b/models/core/_core.yml @@ -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 diff --git a/models/core/revenuecat_subscription_transactions.sql b/models/core/revenuecat_subscription_transactions.sql index f45d551..1f96a2f 100644 --- a/models/core/revenuecat_subscription_transactions.sql +++ b/models/core/revenuecat_subscription_transactions.sql @@ -17,8 +17,15 @@ source as ( {% 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 {{ this }} + where regexp_substr(_file_name, '[0-9]{10}')::timestamp_ntz > ( + select max(_exported_at) + from {{ this }} + ) + ) {% endif %} ), From d71ce39063545b49282d9d5ee6b7391805827e00 Mon Sep 17 00:00:00 2001 From: Jurri Gerretsen <62351599+jurrigerretsen@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:43:29 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Improve=20performance?= =?UTF-8?q?=20of=20incremental=20load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../revenuecat_subscription_transactions.sql | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/models/core/revenuecat_subscription_transactions.sql b/models/core/revenuecat_subscription_transactions.sql index 1f96a2f..906462a 100644 --- a/models/core/revenuecat_subscription_transactions.sql +++ b/models/core/revenuecat_subscription_transactions.sql @@ -2,16 +2,27 @@ 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 where 1=1 {% if var('revenuecat_filter') %} @@ -19,12 +30,8 @@ source as ( {% endif %} {% if is_incremental() %} and store_transaction_id in ( - select store_transaction_id - from {{ this }} - where regexp_substr(_file_name, '[0-9]{10}')::timestamp_ntz > ( - select max(_exported_at) - from {{ this }} - ) + select store_transaction_id + from merge_identifiers ) {% endif %} From 07c3d80fcdfee32ff23992c4ee54664d9d08b6b7 Mon Sep 17 00:00:00 2001 From: Jurri Gerretsen <62351599+jurrigerretsen@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:28:55 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20Remove=20unnecessary=20table?= =?UTF-8?q?=20alias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/core/revenuecat_subscription_transactions.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/core/revenuecat_subscription_transactions.sql b/models/core/revenuecat_subscription_transactions.sql index 906462a..aed3cfd 100644 --- a/models/core/revenuecat_subscription_transactions.sql +++ b/models/core/revenuecat_subscription_transactions.sql @@ -22,7 +22,7 @@ source as ( select * from - {{ source('revenuecat', 'transactions') }} src + {{ source('revenuecat', 'transactions') }} where 1=1 {% if var('revenuecat_filter') %}