-
Notifications
You must be signed in to change notification settings - Fork 0
Created fact_bookings. #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d1a6313
Created fact_bookings sql and yml files. Added a singular test too ma…
EmilyYoung26 ac580ed
Updated sql file to remove select * from CTE and added a unit test fo…
EmilyYoung26 a6e3188
Added null test case to unit test.
EmilyYoung26 2fcd287
Added null test case to unit test.
EmilyYoung26 4c7da12
Added null test case to unit test.
EmilyYoung26 7dc2e36
Corrected unit testing to include a null test.
EmilyYoung26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| with bookings as ( | ||
|
|
||
| select | ||
| booking_id, | ||
| member_id, | ||
| class_id, | ||
| booking_timestamp, | ||
| attendance_status, | ||
| check_in_timestamp, | ||
| cancellation_timestamp | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| 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. | ||
|
|
||
| unit_tests: | ||
| - name: test_fact_bookings_attendance_flags | ||
| description: Test that the attendance_status is consistent with the attendance flags. | ||
| model: fact_bookings | ||
|
|
||
| given: | ||
| - input: ref('stg_bookings') | ||
| rows: | ||
| - {booking_id: 1, member_id: 101, class_id: 1001, booking_timestamp: '2025-01-10 09:00:00', attendance_status: 'attended', check_in_timestamp: '2025-01-10 09:55:00', cancellation_timestamp: null} | ||
| - {booking_id: 2, member_id: 102, class_id: 1002, booking_timestamp: '2025-01-11 10:00:00', attendance_status: 'cancelled', check_in_timestamp: null, cancellation_timestamp: '2025-01-10 15:00:00'} | ||
| - {booking_id: 3, member_id: 103, class_id: 1003, booking_timestamp: '2025-01-12 11:00:00', attendance_status: 'no_show', check_in_timestamp: null, cancellation_timestamp: null} | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add one more test case where attendance_status is just 'null' to begin with, just to check it is handled correctly, otherwise this all looks good :) |
||
| expect: | ||
| rows: | ||
| - {booking_id: 1, member_id: 101, class_id: 1001, booking_timestamp: '2025-01-10 09:00:00', booking_date: '2025-01-10', attendance_status: 'attended', is_attended: true, is_cancelled: false, is_no_show: false, check_in_timestamp: '2025-01-10 09:55:00', cancellation_timestamp: null} | ||
| - {booking_id: 2, member_id: 102, class_id: 1002, booking_timestamp: '2025-01-11 10:00:00', booking_date: '2025-01-11', attendance_status: 'cancelled', is_attended: false, is_cancelled: true, is_no_show: false, check_in_timestamp: null, cancellation_timestamp: '2025-01-10 15:00:00'} | ||
| - {booking_id: 3, member_id: 103, class_id: 1003, booking_timestamp: '2025-01-12 11:00:00', booking_date: '2025-01-12', attendance_status: 'no_show', is_attended: false, is_cancelled: false, is_no_show: true, check_in_timestamp: null, cancellation_timestamp: null} | ||
9 changes: 9 additions & 0 deletions
9
tests/singular_tests/fact_bookings_status_flags_consistent.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.