diff --git a/warehouse/models/mart/ntd/dim_monthly_ntd_ridership_with_adjustments.sql b/warehouse/models/mart/ntd/dim_monthly_ntd_ridership_with_adjustments.sql deleted file mode 100644 index 36d274a8b3..0000000000 --- a/warehouse/models/mart/ntd/dim_monthly_ntd_ridership_with_adjustments.sql +++ /dev/null @@ -1,39 +0,0 @@ -{{ config(materialized="table") }} -with - dim_monthly_ntd_ridership_with_adjustments as ( - select * from {{ ref("int_ntd__monthly_ridership_with_adjustments_joined") }} - ), -ntd_modes as ( - select * from {{ ref("int_ntd__modes") }} -) -select - uza_name, - uace_cd, - _dt, - ts, - ntd_id, - year, - reporter_type, - agency, - mode_type_of_service_status, - mode, - ntd_mode_full_name as mode_full_name, - CASE - WHEN mode IN ('AR', 'CC', 'CR', 'HR', 'YR', 'IP', 'LR', 'MG', 'SR', 'TR', 'MB', 'RB', 'CB', 'TB', 'FB', 'IP', 'MO', 'AG') THEN 'Fixed Route' - WHEN mode IN ('DR', 'DT', 'VP', 'JT', 'PB') THEN 'Demand Response' - ELSE 'Unknown' -- mode is null sometimes - END AS service_type, - _3_mode, - tos, - legacy_ntd_id, - concat(period_year, '-', lpad(period_month, 2, '0')) as period_year_month, - period_year, - period_month, - upt, - vrm, - vrh, - voms -from dim_monthly_ntd_ridership_with_adjustments -LEFT JOIN ntd_modes -ON -dim_monthly_ntd_ridership_with_adjustments.mode = ntd_modes.ntd_mode_abbreviation diff --git a/warehouse/models/mart/ntd/dim_monthly_ridership_with_adjustments.sql b/warehouse/models/mart/ntd/dim_monthly_ridership_with_adjustments.sql new file mode 100644 index 0000000000..c1829f2758 --- /dev/null +++ b/warehouse/models/mart/ntd/dim_monthly_ridership_with_adjustments.sql @@ -0,0 +1,46 @@ +{{ config(materialized="table") }} + +WITH + source AS ( + SELECT * FROM {{ ref("int_ntd__monthly_ridership_with_adjustments_joined") }} + ), + + ntd_modes AS ( + SELECT * FROM {{ ref("int_ntd__modes") }} + ), + + dim_monthly_ridership_with_adjustments AS ( + SELECT {{ dbt_utils.generate_surrogate_key(['ntd_id', 'mode', 'tos', 'period_month', 'period_year']) }} as key, + ntd_id, + legacy_ntd_id, + agency, + reporter_type, + concat(period_year, '-', lpad(period_month, 2, '0')) AS period_year_month, + period_year, + period_month, + uza_name AS primary_uza_name, + uace_cd AS primary_uza_code, + _3_mode, + mode, + ntd_mode_full_name AS mode_name, + CASE + WHEN mode IN ('AG', 'AR', 'CB', 'CC', 'CR', 'FB', 'HR', 'IP', 'IP', 'LR', 'MB', 'MG', 'MO', 'RB', 'SR', 'TB', 'TR', 'YR') + THEN 'Fixed Route' + WHEN mode IN ('DR', 'DT', 'VP', 'JT', 'PB') + THEN 'Demand Response' + ELSE 'Unknown' -- mode is null sometimes + END AS service_type, + mode_type_of_service_status, + tos, + upt, + vrm, + vrh, + voms, + _dt, + execution_ts + FROM source + LEFT JOIN ntd_modes + ON source.mode = ntd_modes.ntd_mode_abbreviation + ) + +SELECT * FROM dim_monthly_ridership_with_adjustments