Skip to content
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

Add agency information to fct_payments_rides_v2 #3008

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions warehouse/models/mart/payments/_payments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ models:
description: The route_long_name of the first tap transaction
- name: route_short_name
description: The route_short_name of the first tap transaction
- name: agency_id
description: |
Agency for the specified route.

This field is required when the dataset provides data for routes from more than one agency in agency.txt, otherwise it is optional.
- name: agency_name
description: Full name of the transit agency.
- name: direction
description: The direction of the first tap transaction
- name: vehicle_id
Expand Down
16 changes: 14 additions & 2 deletions warehouse/models/mart/payments/fct_payments_rides_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ dim_routes AS (
SELECT * FROM {{ ref('dim_routes') }}
),

dim_agency AS (
SELECT * FROM {{ ref('dim_agency') }}
),

dim_gtfs_datasets AS (
SELECT * FROM {{ ref('dim_gtfs_datasets') }}
),
Expand Down Expand Up @@ -124,20 +128,25 @@ stg_littlepay__product_data AS (
FROM {{ ref('stg_littlepay__product_data') }}
),

participants_to_routes AS (
participants_to_routes_and_agency AS (
SELECT
pf.participant_id,
f.date,
r.route_id,
r.route_short_name,
r.route_long_name,
a.agency_id,
a.agency_name,
FROM payments_gtfs_datasets AS pf
LEFT JOIN dim_gtfs_datasets d
ON pf.gtfs_dataset_source_record_id = d.source_record_id
LEFT JOIN fct_daily_schedule_feeds AS f
ON d.key = f.gtfs_dataset_key
LEFT JOIN dim_routes AS r
ON f.feed_key = r.feed_key
LEFT JOIN dim_agency AS a
ON r.agency_id = a.agency_id
AND r.feed_key = r.feed_key
),

debited_micropayments AS (
Expand Down Expand Up @@ -292,6 +301,8 @@ join_table AS (
-- Common transaction info
r.route_long_name,
r.route_short_name,
r.agency_id,
r.agency_name,
t1.direction,
t1.vehicle_id,
t1.littlepay_transaction_id,
Expand Down Expand Up @@ -348,12 +359,13 @@ join_table AS (
LEFT JOIN stg_littlepay__product_data AS p
ON m.participant_id = p.participant_id
AND a.product_id = p.product_id
LEFT JOIN participants_to_routes AS r
LEFT JOIN participants_to_routes_and_agency AS r
ON r.participant_id = m.participant_id
-- here, can just use t1 because transaction date will be populated
-- (don't have to handle unkowns the way we do with route_id)
AND EXTRACT(DATE FROM TIMESTAMP(t1.transaction_date_time_utc)) = r.date
AND r.route_id = COALESCE(t1.route_id, t2.route_id)

),

fct_payments_rides_v2 AS (
Expand Down