dbt
Saas containerization
Daily Subscriptions Accumulation
Daily Subscriptions Accumulation model for saas containerization.
inferred
Blocks
daily_subscriptions_accumulation.sql · 60 lines
inferred
-- models/daily_subscriptions_accumulation.sql
{{ config(materialized='view') }}
select
z.date_created as created,
z.type,
sum(z.count) over (partition by z.type order by z.date_created rows between unbounded preceding and current row) as daily_accum_sum
from
(
select
z.date_created,
z.type,
coalesce(y.count,0) as count
from
(
select
a.date_created,
b.name as type
from
(
select
cast(created as date) as date_created
from
billing_subscription
group by 1
) as a
cross join
(
select
name
from
billing_plan
group by 1
) as b
) as z
left join
(
select
cast(a.created as date) as date_created,
b.name as type,
count(*) as count
from
billing_subscription as a
left join
billing_plan as b
on a.plan_id = b.id
group by 1,2
) as y
on z.date_created = y.date_created
and z.type = y.type
) as z
# models/schema.yml
version: 2
models:
- name: daily_subscriptions_accumulation
columns:
- name: created
- name: type
Assumptions
- materialized='view' is the default; no persist hint found.
- schema.yml columns come from view dimensions; a primary_key dimension gets unique + not_null tests.
daily_subscriptions_accumulation.sql · 48 lines
source-preserved
validation: parses
select
z.date_created as created,
z.type,
sum(z.count) over (partition by z.type order by z.date_created rows between unbounded preceding and current row) as daily_accum_sum
from
(
select
z.date_created,
z.type,
coalesce(y.count,0) as count
from
(
select
a.date_created,
b.name as type
from
(
select
cast(created as date) as date_created
from
billing_subscription
group by 1
) as a
cross join
(
select
name
from
billing_plan
group by 1
) as b
) as z
left join
(
select
cast(a.created as date) as date_created,
b.name as type,
count(*) as count
from
billing_subscription as a
left join
billing_plan as b
on a.plan_id = b.id
group by 1,2
) as y
on z.date_created = y.date_created
and z.type = y.type
) as z
daily_subscriptions_accumulation.view.lkml · 66 lines
inferred
view: daily_subscriptions_accumulation {
derived_table: {
sql: select
z.date_created as created,
z.type,
sum(z.count) over (partition by z.type order by z.date_created rows between unbounded preceding and current row) as daily_accum_sum
from
(
select
z.date_created,
z.type,
coalesce(y.count,0) as count
from
(
select
a.date_created,
b.name as type
from
(
select
cast(created as date) as date_created
from
billing_subscription
group by 1
) as a
cross join
(
select
name
from
billing_plan
group by 1
) as b
) as z
left join
(
select
cast(a.created as date) as date_created,
b.name as type,
count(*) as count
from
billing_subscription as a
left join
billing_plan as b
on a.plan_id = b.id
group by 1,2
) as y
on z.date_created = y.date_created
and z.type = y.type
) as z ;;
}
dimension: created {
type: time
sql: ${TABLE}.created ;;
}
dimension: type {
sql: ${TABLE}.type ;;
}
measure: daily_accum_sum {
type: sum
sql: ${TABLE}.daily_accum_sum ;;
}
}
daily_subscriptions_accumulation.view.lookml · 59 lines
source-preserved
- view: daily_subscriptions_accumulation
derived_table:
sql: select
z.date_created as created,
z.type,
sum(z.count) over (partition by z.type order by z.date_created rows between unbounded preceding and current row) as daily_accum_sum
from
(
select
z.date_created,
z.type,
coalesce(y.count,0) as count
from
(
select
a.date_created,
b.name as type
from
(
select
cast(created as date) as date_created
from
billing_subscription
group by 1
) as a
cross join
(
select
name
from
billing_plan
group by 1
) as b
) as z
left join
(
select
cast(a.created as date) as date_created,
b.name as type,
count(*) as count
from
billing_subscription as a
left join
billing_plan as b
on a.plan_id = b.id
group by 1,2
) as y
on z.date_created = y.date_created
and z.type = y.type
) as z
fields:
- dimension: created
type: time
sql: ${TABLE}.created
- dimension: type
sql: ${TABLE}.type
- measure: daily_accum_sum
type: sum
sql: ${TABLE}.daily_accum_sum
Contents
- daily_subscriptions_accumulation.sql
- daily_subscriptions_accumulation.sql
- daily_subscriptions_accumulation.view.lkml
- daily_subscriptions_accumulation.view.lookml