Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions models/marts/fact_bookings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
with bookings as (

select *
from {{ ref('stg_bookings') }}

),

final as (

select
booking_id,
member_id,
class_id,

booking_timestamp,
date(booking_timestamp) as booking_date,

attendance_status,

case when attendance_status = 'attended' then true else false end as is_attended,
case when attendance_status = 'cancelled' then true else false end as is_cancelled,
case when attendance_status = 'no_show' then true else false end as is_no_show,

check_in_timestamp,
cancellation_timestamp

from bookings

)

select *
from final
78 changes: 78 additions & 0 deletions models/marts/fact_bookings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: 2

models:
- name: fact_bookings
description: Final fact table for class bookings with one row per booking.

columns:
- name: booking_id
description: Unique identifier for each booking.
tests:
- not_null
- unique

- name: member_id
description: Identifier for the member who made the booking.
tests:
- not_null
- relationships:
arguments:
to: ref('dim_members')
field: member_id

- name: class_id
description: Identifier for the class that was booked.
tests:
- not_null

- name: booking_timestamp
description: Timestamp of when the booking was made.
tests:
- not_null

- name: booking_date
description: Date when the booking was made.
tests:
- not_null

- name: attendance_status
description: Cleaned attendance status for the booking.
tests:
- not_null
- accepted_values:
arguments:
values: ['attended', 'cancelled', 'no_show']

- name: is_attended
description: Flag indicating whether the booking was attended.
tests:
- not_null
- accepted_values:
arguments:
values: [true, false]
quote: false

- name: is_cancelled
description: Flag indicating whether the booking was cancelled.
tests:
- not_null
- accepted_values:
arguments:
values: [true, false]
quote: false

- name: is_no_show
description: Flag indicating whether the booking was a no-show.
tests:
- not_null
- accepted_values:
arguments:
values: [true, false]
quote: false

- name: check_in_timestamp
description: Timestamp when the member checked in, if they attended.

- name: cancellation_timestamp
description: Timestamp when the booking was cancelled, if cancelled.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
select *
from {{ ref('fact_bookings') }}
where
(attendance_status = 'attended' and (is_attended = false or is_cancelled = true or is_no_show = true))
or
(attendance_status = 'cancelled' and (is_attended = true or is_cancelled = false or is_no_show = true))
or
(attendance_status = 'no_show' and (is_attended = true or is_cancelled = true or is_no_show = false))

Loading