diff --git a/warehouse/models/mart/gtfs/fct_service_alerts_trip_summaries.sql b/warehouse/models/mart/gtfs/fct_service_alerts_trip_summaries.sql index 3fda0f6004..102034440c 100644 --- a/warehouse/models/mart/gtfs/fct_service_alerts_trip_summaries.sql +++ b/warehouse/models/mart/gtfs/fct_service_alerts_trip_summaries.sql @@ -12,8 +12,18 @@ }} WITH service_alerts AS ( - SELECT * FROM {{ ref('fct_service_alert_informed_entities') }} + SELECT + entities.*, + -- per spec, start/end is +/- infinity if null: https://gtfs.org/realtime/reference/#message-timerange + -- use placeholders instead + COALESCE(TIMESTAMP_SECONDS(unnested_active_period.start), TIMESTAMP(DATE(1900,1,1))) AS active_period_start_ts, + COALESCE(TIMESTAMP_SECONDS(unnested_active_period.end), TIMESTAMP(DATE(2099,1,1))) AS active_period_end_ts + FROM {{ ref('fct_service_alert_informed_entities') }} entities + LEFT JOIN UNNEST(active_period) AS unnested_active_period, WHERE {{ gtfs_rt_dt_where() }} + -- TODO: support route_id/direction_id/start_time as a trip identifier + -- as of 2023-04-20, there are no cases of service alert messages where trip ID is not populated and trip.route ID is populated + AND trip_id IS NOT NULL ), fct_service_alerts_trip_summaries AS ( @@ -28,7 +38,12 @@ fct_service_alerts_trip_summaries AS ( 'trip_start_time', 'trip_start_date', ]) }} as key, - dt, + -- TODO: once #2457 merges, we should use the schedule feed timezone rather than just Pacific + -- we need to get individual trip instances that can be merged with schedule feed trip instances + COALESCE( + PARSE_DATE("%Y%m%d",trip_start_date), + DATE(header_timestamp, "America/Los_Angeles"), + DATE(_extract_ts, "America/Los_Angeles")) AS calculated_service_date_pacific, base64_url, trip_id, trip_route_id, diff --git a/warehouse/models/mart/gtfs/fct_trip_updates_messages.sql b/warehouse/models/mart/gtfs/fct_trip_updates_messages.sql index 8278abb2b6..bac2301554 100644 --- a/warehouse/models/mart/gtfs/fct_trip_updates_messages.sql +++ b/warehouse/models/mart/gtfs/fct_trip_updates_messages.sql @@ -46,7 +46,7 @@ fct_trip_updates_messages AS ( PARSE_DATE("%Y%m%d",trip_start_date), DATE(trip_update_timestamp, "America/Los_Angeles"), DATE(header_timestamp, "America/Los_Angeles"), - DATE(_extract_ts)) AS calculated_service_date_pacific, + DATE(_extract_ts, "America/Los_Angeles")) AS calculated_service_date_pacific, header_timestamp, header_version,