From a7f55aa93f54f8b888780497720609939723e7f9 Mon Sep 17 00:00:00 2001 From: dgitis Date: Wed, 18 Oct 2023 15:07:18 -0700 Subject: [PATCH] code cleanup --- .../stg_ga4__event_purchase_deduplicated.sql | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/models/staging/recommended_events/stg_ga4__event_purchase_deduplicated.sql b/models/staging/recommended_events/stg_ga4__event_purchase_deduplicated.sql index 30581d80..ce5aeae1 100644 --- a/models/staging/recommended_events/stg_ga4__event_purchase_deduplicated.sql +++ b/models/staging/recommended_events/stg_ga4__event_purchase_deduplicated.sql @@ -17,22 +17,11 @@ with purch as ( {% if not flags.FULL_REFRESH %} where event_date_dt in ({{ partitions_to_query | join(',') }}) {% endif %} -) -, dedup as ( - /* this is intended to be the maximally performant MVP for transaction deduplication - it is possible that you may want to roll up various purchase parameters and not just event_key where later events contain late-arriving parameters - in cases like this, use this model as a template and make your customizations in your project */ - select distinct - first_value(event_key ignore nulls) over (transaction_window) as event_key - from purch - window transaction_window as ( - partition by transaction_id - order by - event_timestamp asc rows between unbounded preceding - and unbounded following - ) + qualify row_number() over( + partition by transaction_id + order by event_timestamp + ) = 1 ) select - purch.* -from dedup -left join purch on dedup.event_key = purch.event_key \ No newline at end of file + * +from purch