Skip to content

Commit

Permalink
Fix missing churned_on_pt dates because of uninstalls and other condi…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
JonCrawford committed Jan 5, 2024
1 parent 51e2c7e commit 7dce916
Show file tree
Hide file tree
Showing 7 changed files with 702 additions and 686 deletions.
2 changes: 1 addition & 1 deletion .sqlfluff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[sqlfluff]
templater = dbt
dialect = snowflake
exclude_rules = L010, L027, L030, L032, layout.indent, layout.cte_bracket, layout.select_targets, ST06, CV11
exclude_rules = L010, L027, L030, L032, layout.indent, layout.cte_bracket, layout.select_targets, ST06, CV11, AM06
verbose = 0
max_line_length = 160
large_file_skip_byte_limit = 40000
Expand Down
2 changes: 1 addition & 1 deletion mesa_dbt.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"sqlfluff.format.enabled": false,
"sqlfluff.suppressNotifications": false,
"dbt.queryLimit": 20,
"dbt.queryLimit": 200,
"dbt.queryPreview.queryLimit": 250,
"sqlfluff.osmosis.enabled": false,
"files.trimTrailingWhitespace": true,
Expand Down
66 changes: 33 additions & 33 deletions models/mesa/intermediate/int_shop_calendar.sql
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
with
shops as (select shop_subdomain, is_custom_app from {{ ref("stg_shops") }}),
WITH
shops AS (SELECT shop_subdomain, is_custom_app FROM {{ ref("stg_shops") }}),

shop_plan_days as (select * from {{ ref("int_mesa_shop_plan_days") }}),
shop_plan_days AS (SELECT * FROM {{ ref("int_mesa_shop_plan_days") }}),

shop_lifespans as (select * from {{ ref("int_shop_lifespans") }}),
shop_lifespans AS (SELECT * FROM {{ ref("int_shop_lifespans") }}),

calendar_dates as (
select date_day as dt
from {{ ref("calendar_dates") }}
where
dt <= {{ pacific_timestamp("CURRENT_TIMESTAMP") }}::date - interval '1 DAY'
calendar_dates AS (
SELECT date_day AS dt
FROM {{ ref("calendar_dates") }}
WHERE
dt <= {{ pacific_timestamp("CURRENT_TIMESTAMP") }}::DATE - INTERVAL '1 DAY'
),

shop_trial_days as (
select shop_subdomain, dt, true as is_in_trial
from calendar_dates
inner join
shop_trial_days AS (
SELECT shop_subdomain, dt, TRUE AS is_in_trial
FROM calendar_dates
INNER JOIN
{{ ref("stg_trial_periods") }}
on calendar_dates.dt between started_on_pt and coalesce(
ended_on_pt, {{ pacific_timestamp("CURRENT_DATE") }}::date
ON calendar_dates.dt BETWEEN started_on_pt AND COALESCE(
ended_on_pt, {{ pacific_timestamp("CURRENT_TIMESTAMP") }}::DATE - INTERVAL '1 DAY'
)
),

shop_calendar as (
select
shop_calendar AS (
SELECT
shop_subdomain,
dt,
coalesce(
iff(
is_shopify_zombie_plan or coalesce(is_in_trial, false),
COALESCE(
IFF(
is_shopify_zombie_plan OR COALESCE(is_in_trial, FALSE),
0,
daily_plan_revenue
),
0
) as daily_plan_revenue,
) AS daily_plan_revenue,
mesa_plan,
mesa_plan_identifier,
coalesce(shopify_plan, 'unavailable') as shopify_plan,
coalesce(shop_trial_days.is_in_trial, false) as is_in_trial,
coalesce(is_shopify_zombie_plan, false) as is_shopify_zombie_plan
COALESCE(shopify_plan, 'unavailable') AS shopify_plan,
COALESCE(shop_trial_days.is_in_trial, FALSE) AS is_in_trial,
COALESCE(is_shopify_zombie_plan, FALSE) AS is_shopify_zombie_plan

from shop_lifespans
inner join calendar_dates on dt between first_dt and last_dt
left join shop_plan_days using (shop_subdomain, dt)
left join shops using (shop_subdomain)
left join shop_trial_days using (shop_subdomain, dt)
order by dt
FROM shop_lifespans
INNER JOIN calendar_dates ON dt BETWEEN first_dt AND last_dt
LEFT JOIN shop_plan_days USING (shop_subdomain, dt)
LEFT JOIN shops USING (shop_subdomain)
LEFT JOIN shop_trial_days USING (shop_subdomain, dt)
ORDER BY dt
)

select *
from shop_calendar
order by shop_subdomain, dt
SELECT *
FROM shop_calendar
ORDER BY shop_subdomain, dt
1 change: 0 additions & 1 deletion models/mesa/intermediate/int_shop_install_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,3 @@ SELECT
ELSE 'Other'
END AS unified_landing_surface_area
FROM final
WHERE unified_traffic_source IS NOT NULL
11 changes: 10 additions & 1 deletion models/mesa/marts/_shops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,9 @@ models:
- description: The date/time the Shop received their first journey email.
name: first_journey_sent_at_pt
- description: Whether the Shop has churned.
name: has_churned
name: has_churned_paid
- name: has_churned_during_trial
description: Whether the Shop has churned during trial.
- description: The identifier of the Shop's first trial plan.
name: first_trial_plan_identifier
- description: The status of the Shop's plan upgrade funnel through trial, paying and churn.
Expand Down Expand Up @@ -646,6 +648,11 @@ models:
name: churned_customer_duration_in_days
- description: The date the Shop churned.
name: churned_on_pt
tests:
- not_null:
config:
where: "NOT is_custom_app AND has_churned_paid"
error_if: ">100"
- description: The number of weeks the Shop has been/was on a paid plan.
name: churned_customer_duration_in_weeks
- description: The number of months the Shop has been on a paid plan.
Expand Down Expand Up @@ -737,3 +744,5 @@ models:
description: Whether there was an organic click in the app store during acquisition.
- name: acq_app_store_has_ad_click
description: Whether there was an ad click in the app store during acquisition.
- name: acq_unified_landing_surface_area
description: The type of page the user first landed on during acquisition.
Loading

0 comments on commit 7dce916

Please sign in to comment.