-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add service alert trip summaries and fix typos
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
warehouse/models/intermediate/gtfs/int_gtfs_rt__service_alerts_trip_summaries.sql
This file contains 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,53 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
incremental_strategy='insert_overwrite', | ||
partition_by={ | ||
'field': 'dt', | ||
'data_type': 'date', | ||
'granularity': 'day', | ||
}, | ||
cluster_by='base64_url', | ||
) | ||
}} | ||
|
||
{% if is_incremental() %} | ||
{% set timestamps = dbt_utils.get_column_values(table=this, column='dt', order_by = 'dt DESC', max_records = 1) %} | ||
{% set max_ts = timestamps[0] %} | ||
{% endif %} | ||
|
||
WITH service_alerts AS ( | ||
SELECT * FROM {{ ref('fct_service_alert_informed_entities') }} | ||
{% if is_incremental() %} | ||
WHERE dt >= EXTRACT(DATE FROM TIMESTAMP('{{ max_ts }}')) | ||
{% else %} | ||
WHERE dt >= DATE_SUB(CURRENT_DATE(), INTERVAL {{ var('TRIP_UPDATES_LOOKBACK_DAYS') }} DAY) | ||
{% endif %} | ||
), | ||
|
||
int_gtfs_rt__service_alerts_trip_summaries AS ( | ||
SELECT | ||
-- https://gtfs.org/realtime/reference/#message-tripdescriptor | ||
{{ dbt_utils.surrogate_key([ | ||
'dt', | ||
'base64_url', | ||
'trip_id', | ||
'trip_route_id', | ||
'trip_direction_id', | ||
'trip_start_time', | ||
'trip_start_date', | ||
]) }} as key, | ||
dt, | ||
base64_url, | ||
trip_id, | ||
trip_route_id, | ||
trip_direction_id, | ||
trip_start_time, | ||
trip_start_date, | ||
COUNT(DISTINCT id) AS num_distinct_message_ids, | ||
ARRAY_AGG(DISTINCT service_alert_message_key) AS service_alert_message_keys, | ||
FROM service_alerts | ||
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8 | ||
) | ||
|
||
SELECT * FROM int_gtfs_rt__service_alerts_trip_summaries |
This file contains 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
This file contains 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
This file contains 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