diff --git a/warehouse/models/mart/ntd_annual_reporting/dim_2022_agency_information.sql b/warehouse/models/mart/ntd_annual_reporting/dim_2022_agency_information.sql index a769ad2404..288d8b30e4 100644 --- a/warehouse/models/mart/ntd_annual_reporting/dim_2022_agency_information.sql +++ b/warehouse/models/mart/ntd_annual_reporting/dim_2022_agency_information.sql @@ -3,9 +3,21 @@ WITH staging_agency_information AS ( FROM {{ ref('stg_ntd__2022_agency_information') }} ), -dim_2022_agency_information AS ( +dim_organizations AS ( + SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current + +), + +dim_2022_agency_information AS ( + SELECT + staging_agency_information.*, + dim_organizations.caltrans_district FROM staging_agency_information + LEFT JOIN dim_organizations + ON staging_agency_information.ntd_id = dim_organizations.ntd_id_2022 ) SELECT @@ -51,6 +63,7 @@ SELECT reported_by_ntd_id, density, state_parent_ntd_id, + caltrans_district, dt, execution_ts FROM dim_2022_agency_information diff --git a/warehouse/models/mart/ntd_annual_reporting/dim_2023_agency_information.sql b/warehouse/models/mart/ntd_annual_reporting/dim_2023_agency_information.sql index d1ef108f79..cef86bfb15 100644 --- a/warehouse/models/mart/ntd_annual_reporting/dim_2023_agency_information.sql +++ b/warehouse/models/mart/ntd_annual_reporting/dim_2023_agency_information.sql @@ -3,9 +3,21 @@ WITH staging_agency_information AS ( FROM {{ ref('stg_ntd__2023_agency_information') }} ), -dim_2023_agency_information AS ( +dim_organizations AS ( + SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current + +), + +dim_2023_agency_information AS ( + SELECT + staging_agency_information.*, + dim_organizations.caltrans_district FROM staging_agency_information + LEFT JOIN dim_organizations + ON staging_agency_information.ntd_id = dim_organizations.ntd_id ) SELECT diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_2023_contractual_relationships.sql b/warehouse/models/mart/ntd_annual_reporting/fct_2023_contractual_relationships.sql index 60dfd453bd..79829d7c6a 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_2023_contractual_relationships.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_2023_contractual_relationships.sql @@ -3,9 +3,21 @@ WITH staging_contractual_relationships AS ( FROM {{ ref('stg_ntd__2023_contractual_relationships') }} ), -fct_2023_contractual_relationships AS ( +dim_organizations AS ( + SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current + +), + +fct_2023_contractual_relationships AS ( + SELECT + staging_contractual_relationships.*, + dim_organizations.caltrans_district FROM staging_contractual_relationships + LEFT JOIN dim_organizations + ON staging_contractual_relationships.ntd_id = dim_organizations.ntd_id ) SELECT diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns.sql b/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns.sql index cedb7985f8..1e21ccbef0 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns.sql @@ -3,9 +3,24 @@ WITH staging_breakdowns AS ( FROM {{ ref('stg_ntd__breakdowns') }} ), -fct_breakdowns AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_breakdowns AS ( + SELECT + staging_breakdowns.*, + dim_organizations.caltrans_district FROM staging_breakdowns + LEFT JOIN dim_organizations + ON CASE + WHEN staging_breakdowns.report_year = 2022 THEN + staging_breakdowns.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_breakdowns.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -38,6 +53,7 @@ SELECT vehicle_passenger_car_miles_1, vehicle_passenger_car_miles_2, vehicle_passenger_car_revenue, + caltrans_district, dt, execution_ts FROM fct_breakdowns diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns_by_agency.sql index e415fb9bfc..6c689b81c4 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_breakdowns_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_breakdowns_by_agency AS ( FROM {{ ref('stg_ntd__breakdowns_by_agency') }} ), -fct_breakdowns_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_breakdowns_by_agency AS ( + SELECT + staging_breakdowns_by_agency.*, + dim_organizations.caltrans_district FROM staging_breakdowns_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_breakdowns_by_agency.report_year = 2022 THEN + staging_breakdowns_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_breakdowns_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -33,6 +48,7 @@ SELECT sum_train_revenue_miles, sum_vehicle_passenger_car_miles, sum_vehicle_passenger_car_revenue, + caltrans_district, dt, execution_ts FROM fct_breakdowns_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_capital_use.sql b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_capital_use.sql index d617bfdffb..3ebfa92c30 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_capital_use.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_capital_use.sql @@ -3,9 +3,24 @@ WITH staging_capital_expenses_by_capital_use AS ( FROM {{ ref('stg_ntd__capital_expenses_by_capital_use') }} ), -fct_capital_expenses_by_capital_use AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_capital_expenses_by_capital_use AS ( + SELECT + staging_capital_expenses_by_capital_use.*, + dim_organizations.caltrans_district FROM staging_capital_expenses_by_capital_use + LEFT JOIN dim_organizations + ON CASE + WHEN staging_capital_expenses_by_capital_use.report_year = 2022 THEN + staging_capital_expenses_by_capital_use.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_capital_expenses_by_capital_use.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -47,6 +62,7 @@ SELECT typeofservicecd, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_capital_expenses_by_capital_use diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_mode.sql b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_mode.sql index bd8b8b79cc..366531457b 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_mode.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_by_mode.sql @@ -3,9 +3,24 @@ WITH staging_capital_expenses_by_mode AS ( FROM {{ ref('stg_ntd__capital_expenses_by_mode') }} ), -fct_capital_expenses_by_mode AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_capital_expenses_by_mode AS ( + SELECT + staging_capital_expenses_by_mode.*, + dim_organizations.caltrans_district FROM staging_capital_expenses_by_mode + LEFT JOIN dim_organizations + ON CASE + WHEN staging_capital_expenses_by_mode.report_year = 2022 THEN + staging_capital_expenses_by_mode.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_capital_expenses_by_mode.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -43,6 +58,7 @@ SELECT sum_stations, sum_total, typeofservicecd, + caltrans_district, dt, execution_ts FROM fct_capital_expenses_by_mode diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_existing_service.sql b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_existing_service.sql index d228cc40f2..444eab6040 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_existing_service.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_existing_service.sql @@ -3,9 +3,24 @@ WITH staging_capital_expenses_for_existing_service AS ( FROM {{ ref('stg_ntd__capital_expenses_for_existing_service') }} ), -fct_capital_expenses_for_existing_service AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_capital_expenses_for_existing_service AS ( + SELECT + staging_capital_expenses_for_existing_service.*, + dim_organizations.caltrans_district FROM staging_capital_expenses_for_existing_service + LEFT JOIN dim_organizations + ON CASE + WHEN staging_capital_expenses_for_existing_service.report_year = 2022 THEN + staging_capital_expenses_for_existing_service.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_capital_expenses_for_existing_service.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -32,6 +47,7 @@ SELECT sum_reduced_reporter, sum_stations, sum_total, + caltrans_district, dt, execution_ts FROM fct_capital_expenses_for_existing_service diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_expansion_of_service.sql b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_expansion_of_service.sql index c6f794117c..3b977455d0 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_expansion_of_service.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_capital_expenses_for_expansion_of_service.sql @@ -3,9 +3,24 @@ WITH staging_capital_expenses_for_expansion_of_service AS ( FROM {{ ref('stg_ntd__capital_expenses_for_expansion_of_service') }} ), -fct_capital_expenses_for_expansion_of_service AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_capital_expenses_for_expansion_of_service AS ( + SELECT + staging_capital_expenses_for_expansion_of_service.*, + dim_organizations.caltrans_district FROM staging_capital_expenses_for_expansion_of_service + LEFT JOIN dim_organizations + ON CASE + WHEN staging_capital_expenses_for_expansion_of_service.report_year = 2022 THEN + staging_capital_expenses_for_expansion_of_service.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_capital_expenses_for_expansion_of_service.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -32,6 +47,7 @@ SELECT sum_reduced_reporter, sum_stations, sum_total, + caltrans_district, dt, execution_ts FROM fct_capital_expenses_for_expansion_of_service diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_agency.sql index 4b8bf2e41d..843a2c4f22 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_employees_by_agency AS ( FROM {{ ref('stg_ntd__employees_by_agency') }} ), -fct_employees_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_employees_by_agency AS ( + SELECT + staging_employees_by_agency.*, + dim_organizations.caltrans_district FROM staging_employees_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_employees_by_agency.report_year = 2022 THEN + staging_employees_by_agency.max_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_employees_by_agency.max_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -35,6 +50,7 @@ SELECT total_employees, total_operating_hours, total_salaries, + caltrans_district, dt, execution_ts FROM fct_employees_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode.sql b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode.sql index c4961fa3be..746b3c2e2a 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode.sql @@ -3,9 +3,24 @@ WITH staging_employees_by_mode AS ( FROM {{ ref('stg_ntd__employees_by_mode') }} ), -fct_employees_by_mode AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_employees_by_mode AS ( + SELECT + staging_employees_by_mode.*, + dim_organizations.caltrans_district FROM staging_employees_by_mode + LEFT JOIN dim_organizations + ON CASE + WHEN staging_employees_by_mode.report_year = 2022 THEN + staging_employees_by_mode.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_employees_by_mode.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -28,6 +43,7 @@ SELECT sum_total_employee_count, sum_total_hours, type_of_service, + caltrans_district, dt, execution_ts FROM fct_employees_by_mode diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode_and_employee_type.sql b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode_and_employee_type.sql index 2c846add84..2f8857d8cf 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode_and_employee_type.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_employees_by_mode_and_employee_type.sql @@ -3,9 +3,24 @@ WITH staging_employees_by_mode_and_employee_type AS ( FROM {{ ref('stg_ntd__employees_by_mode_and_employee_type') }} ), -fct_employees_by_mode_and_employee_type AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_employees_by_mode_and_employee_type AS ( + SELECT + staging_employees_by_mode_and_employee_type.*, + dim_organizations.caltrans_district FROM staging_employees_by_mode_and_employee_type + LEFT JOIN dim_organizations + ON CASE + WHEN staging_employees_by_mode_and_employee_type.report_year = 2022 THEN + staging_employees_by_mode_and_employee_type.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_employees_by_mode_and_employee_type.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -48,6 +63,7 @@ SELECT vehicle_operations_count_q, vehicle_operations_hours, vehicle_operations_hours_q, + caltrans_district, dt, execution_ts FROM fct_employees_by_mode_and_employee_type diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy.sql b/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy.sql index 13202f9cb6..d02c94bc9f 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy.sql @@ -3,9 +3,24 @@ WITH staging_fuel_and_energy AS ( FROM {{ ref('stg_ntd__fuel_and_energy') }} ), -fct_fuel_and_energy AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_fuel_and_energy AS ( + SELECT + staging_fuel_and_energy.*, + dim_organizations.caltrans_district FROM staging_fuel_and_energy + LEFT JOIN dim_organizations + ON CASE + WHEN staging_fuel_and_energy.report_year = 2022 THEN + staging_fuel_and_energy.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_fuel_and_energy.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -74,6 +89,7 @@ SELECT typeofservicecd, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_fuel_and_energy diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy_by_agency.sql index 384f3e8881..895f32b588 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_fuel_and_energy_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_fuel_and_energy_by_agency AS ( FROM {{ ref('stg_ntd__fuel_and_energy_by_agency') }} ), -fct_fuel_and_energy_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_fuel_and_energy_by_agency AS ( + SELECT + staging_fuel_and_energy_by_agency.*, + dim_organizations.caltrans_district FROM staging_fuel_and_energy_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_fuel_and_energy_by_agency.report_year = 2022 THEN + staging_fuel_and_energy_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_fuel_and_energy_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -39,6 +54,7 @@ SELECT sum_liquefied_petroleum_gas_gal, sum_other_fuel, sum_other_fuel_gal_gal_equivalent, + caltrans_district, dt, execution_ts FROM fct_fuel_and_energy_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_by_expense_type.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_by_expense_type.sql index 396840c267..66864a0e47 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_by_expense_type.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_by_expense_type.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_by_expense_type AS ( FROM {{ ref('stg_ntd__funding_sources_by_expense_type') }} ), -fct_funding_sources_by_expense_type AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_by_expense_type AS ( + SELECT + staging_funding_sources_by_expense_type.*, + dim_organizations.caltrans_district FROM staging_funding_sources_by_expense_type + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_by_expense_type.report_year = 2022 THEN + staging_funding_sources_by_expense_type.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_by_expense_type.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -33,6 +48,7 @@ SELECT total_questionable, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_by_expense_type diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_directly_generated.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_directly_generated.sql index 1c7bd121fe..5c0f215068 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_directly_generated.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_directly_generated.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_directly_generated AS ( FROM {{ ref('stg_ntd__funding_sources_directly_generated') }} ), -fct_funding_sources_directly_generated AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_directly_generated AS ( + SELECT + staging_funding_sources_directly_generated.*, + dim_organizations.caltrans_district FROM staging_funding_sources_directly_generated + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_directly_generated.report_year = 2022 THEN + staging_funding_sources_directly_generated.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_directly_generated.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -34,6 +49,7 @@ SELECT total_questionable, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_directly_generated diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_federal.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_federal.sql index fcdbab89e3..afaecb97e7 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_federal.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_federal.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_federal AS ( FROM {{ ref('stg_ntd__funding_sources_federal') }} ), -fct_funding_sources_federal AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_federal AS ( + SELECT + staging_funding_sources_federal.*, + dim_organizations.caltrans_district FROM staging_funding_sources_federal + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_federal.report_year = 2022 THEN + staging_funding_sources_federal.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_federal.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -27,6 +42,7 @@ SELECT total_federal_funds, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_federal diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_local.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_local.sql index 10f9e3e062..6ed7158022 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_local.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_local.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_local AS ( FROM {{ ref('stg_ntd__funding_sources_local') }} ), -fct_funding_sources_local AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_local AS ( + SELECT + staging_funding_sources_local.*, + dim_organizations.caltrans_district FROM staging_funding_sources_local + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_local.report_year = 2022 THEN + staging_funding_sources_local.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_local.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -30,6 +45,7 @@ SELECT total, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_local diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_state.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_state.sql index 6ee2cad9b1..96eec90b7e 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_state.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_state.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_state AS ( FROM {{ ref('stg_ntd__funding_sources_state') }} ), -fct_funding_sources_state AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_state AS ( + SELECT + staging_funding_sources_state.*, + dim_organizations.caltrans_district FROM staging_funding_sources_state + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_state.report_year = 2022 THEN + staging_funding_sources_state.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_state.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -25,6 +40,7 @@ SELECT transportation_funds, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_state diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_taxes_levied_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_taxes_levied_by_agency.sql index 6d264e897a..86d17be78b 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_taxes_levied_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_funding_sources_taxes_levied_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_funding_sources_taxes_levied_by_agency AS ( FROM {{ ref('stg_ntd__funding_sources_taxes_levied_by_agency') }} ), -fct_funding_sources_taxes_levied_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_funding_sources_taxes_levied_by_agency AS ( + SELECT + staging_funding_sources_taxes_levied_by_agency.*, + dim_organizations.caltrans_district FROM staging_funding_sources_taxes_levied_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_funding_sources_taxes_levied_by_agency.report_year = 2022 THEN + staging_funding_sources_taxes_levied_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_funding_sources_taxes_levied_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -28,6 +43,7 @@ SELECT total, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_funding_sources_taxes_levied_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities.sql b/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities.sql index 2491817c25..78d0882666 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities.sql @@ -3,9 +3,24 @@ WITH staging_maintenance_facilities AS ( FROM {{ ref('stg_ntd__maintenance_facilities') }} ), -fct_maintenance_facilities AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_maintenance_facilities AS ( + SELECT + staging_maintenance_facilities.*, + dim_organizations.caltrans_district FROM staging_maintenance_facilities + LEFT JOIN dim_organizations + ON CASE + WHEN staging_maintenance_facilities.report_year = 2022 THEN + staging_maintenance_facilities.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_maintenance_facilities.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -48,6 +63,7 @@ SELECT under_200_vehicles, under_200_vehicles_1, uza_name, + caltrans_district, dt, execution_ts FROM fct_maintenance_facilities diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities_by_agency.sql index efd3323148..ed4639f43f 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_maintenance_facilities_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_maintenance_facilities_by_agency AS ( FROM {{ ref('stg_ntd__maintenance_facilities_by_agency') }} ), -fct_maintenance_facilities_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_maintenance_facilities_by_agency AS ( + SELECT + staging_maintenance_facilities_by_agency.*, + dim_organizations.caltrans_district FROM staging_maintenance_facilities_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_maintenance_facilities_by_agency.report_year = 2022 THEN + staging_maintenance_facilities_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_maintenance_facilities_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -32,6 +47,7 @@ SELECT sum_owned_by_public_agency, sum_total_facilities, sum_under_200_vehicles, + caltrans_district, dt, execution_ts FROM fct_maintenance_facilities_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_metrics.sql b/warehouse/models/mart/ntd_annual_reporting/fct_metrics.sql index b3cf3dc2e7..42ac658eab 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_metrics.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_metrics.sql @@ -3,9 +3,24 @@ WITH staging_metrics AS ( FROM {{ ref('stg_ntd__metrics') }} ), -fct_metrics AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_metrics AS ( + SELECT + staging_metrics.*, + dim_organizations.caltrans_district FROM staging_metrics + LEFT JOIN dim_organizations + ON CASE + WHEN staging_metrics.report_year = 2022 THEN + staging_metrics.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_metrics.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -48,6 +63,7 @@ SELECT vehicle_revenue_miles_1, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_metrics diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function.sql b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function.sql index 99810cac9c..f32560b725 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function.sql @@ -3,9 +3,24 @@ WITH staging_operating_expenses_by_function AS ( FROM {{ ref('stg_ntd__operating_expenses_by_function') }} ), -fct_operating_expenses_by_function AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_operating_expenses_by_function AS ( + SELECT + staging_operating_expenses_by_function.*, + dim_organizations.caltrans_district FROM staging_operating_expenses_by_function + LEFT JOIN dim_organizations + ON CASE + WHEN staging_operating_expenses_by_function.report_year = 2022 THEN + staging_operating_expenses_by_function.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_operating_expenses_by_function.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -38,6 +53,7 @@ SELECT vehicle_operations_1, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_operating_expenses_by_function diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function_and_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function_and_agency.sql index 1c05549b75..c48840e31d 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function_and_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_function_and_agency.sql @@ -3,9 +3,24 @@ WITH staging_operating_expenses_by_function_and_agency AS ( FROM {{ ref('stg_ntd__operating_expenses_by_function_and_agency') }} ), -fct_operating_expenses_by_function_and_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_operating_expenses_by_function_and_agency AS ( + SELECT + staging_operating_expenses_by_function_and_agency.*, + dim_organizations.caltrans_district FROM staging_operating_expenses_by_function_and_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_operating_expenses_by_function_and_agency.report_year = 2022 THEN + staging_operating_expenses_by_function_and_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_operating_expenses_by_function_and_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -27,6 +42,7 @@ SELECT sum_vehicle_maintenance, sum_vehicle_operations, total, + caltrans_district, dt, execution_ts FROM fct_operating_expenses_by_function_and_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type.sql b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type.sql index 4e916c8817..63d04560f0 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type.sql @@ -3,9 +3,24 @@ WITH staging_operating_expenses_by_type AS ( FROM {{ ref('stg_ntd__operating_expenses_by_type') }} ), -fct_operating_expenses_by_type AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_operating_expenses_by_type AS ( + SELECT + staging_operating_expenses_by_type.*, + dim_organizations.caltrans_district FROM staging_operating_expenses_by_type + LEFT JOIN dim_organizations + ON CASE + WHEN staging_operating_expenses_by_type.report_year = 2022 THEN + staging_operating_expenses_by_type.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_operating_expenses_by_type.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -58,6 +73,7 @@ SELECT utilities, utilities_questionable, uza_name, + caltrans_district, dt, execution_ts FROM fct_operating_expenses_by_type diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type_and_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type_and_agency.sql index 712f32a9b6..33af9d45fb 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type_and_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_operating_expenses_by_type_and_agency.sql @@ -3,9 +3,24 @@ WITH staging_operating_expenses_by_type_and_agency AS ( FROM {{ ref('stg_ntd__operating_expenses_by_type_and_agency') }} ), -fct_operating_expenses_by_type_and_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_operating_expenses_by_type_and_agency AS ( + SELECT + staging_operating_expenses_by_type_and_agency.*, + dim_organizations.caltrans_district FROM staging_operating_expenses_by_type_and_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_operating_expenses_by_type_and_agency.report_year = 2022 THEN + staging_operating_expenses_by_type_and_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_operating_expenses_by_type_and_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -37,6 +52,7 @@ SELECT sum_tires, sum_total, sum_utilities, + caltrans_district, dt, execution_ts FROM fct_operating_expenses_by_type_and_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_agency.sql index 6b8b002999..6693d44124 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_service_by_agency AS ( FROM {{ ref('stg_ntd__service_by_agency') }} ), -fct_service_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_service_by_agency AS ( + SELECT + staging_service_by_agency.*, + dim_organizations.caltrans_district FROM staging_service_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_service_by_agency.report_year = 2022 THEN + staging_service_by_agency._5_digit_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_service_by_agency._5_digit_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -44,6 +59,7 @@ SELECT sum_train_revenue_miles, sum_trains_in_operation, sum_unlinked_passenger_trips_upt, + caltrans_district, dt, execution_ts FROM fct_service_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode.sql b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode.sql index 75c9901449..c046c273a0 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode.sql @@ -3,9 +3,24 @@ WITH staging_service_by_mode AS ( FROM {{ ref('stg_ntd__service_by_mode') }} ), -fct_service_by_mode AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_service_by_mode AS ( + SELECT + staging_service_by_mode.*, + dim_organizations.caltrans_district FROM staging_service_by_mode + LEFT JOIN dim_organizations + ON CASE + WHEN staging_service_by_mode.report_year = 2022 THEN + staging_service_by_mode._5_digit_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_service_by_mode._5_digit_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -55,6 +70,7 @@ SELECT sum_trains_in_operation, sum_unlinked_passenger_trips_upt, type_of_service, + caltrans_district, dt, execution_ts FROM fct_service_by_mode diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode_and_time_period.sql b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode_and_time_period.sql index 9b5ca4776d..3454cb29cb 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode_and_time_period.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_service_by_mode_and_time_period.sql @@ -3,9 +3,24 @@ WITH staging_service_by_mode_and_time_period AS ( FROM {{ ref('stg_ntd__service_by_mode_and_time_period') }} ), -fct_service_by_mode_and_time_period AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_service_by_mode_and_time_period AS ( + SELECT + staging_service_by_mode_and_time_period.*, + dim_organizations.caltrans_district FROM staging_service_by_mode_and_time_period + LEFT JOIN dim_organizations + ON CASE + WHEN staging_service_by_mode_and_time_period.report_year = 2022 THEN + staging_service_by_mode_and_time_period._5_digit_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_service_by_mode_and_time_period._5_digit_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -78,6 +93,7 @@ SELECT vehicle_miles_questionable, vehicle_revenue_hours_questionable, vehicle_revenue_miles_questionable, + caltrans_district, dt, execution_ts FROM fct_service_by_mode_and_time_period diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_stations_and_facilities_by_agency_and_facility_type.sql b/warehouse/models/mart/ntd_annual_reporting/fct_stations_and_facilities_by_agency_and_facility_type.sql index 5221252d3a..9efcc9bebc 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_stations_and_facilities_by_agency_and_facility_type.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_stations_and_facilities_by_agency_and_facility_type.sql @@ -3,9 +3,24 @@ WITH staging_stations_and_facilities_by_agency_and_facility_type AS ( FROM {{ ref('stg_ntd__stations_and_facilities_by_agency_and_facility_type') }} ), -fct_stations_and_facilities_by_agency_and_facility_type AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_stations_and_facilities_by_agency_and_facility_type AS ( + SELECT + staging_stations_and_facilities_by_agency_and_facility_type.*, + dim_organizations.caltrans_district FROM staging_stations_and_facilities_by_agency_and_facility_type + LEFT JOIN dim_organizations + ON CASE + WHEN staging_stations_and_facilities_by_agency_and_facility_type.report_year = 2022 THEN + staging_stations_and_facilities_by_agency_and_facility_type.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_stations_and_facilities_by_agency_and_facility_type.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -46,6 +61,7 @@ SELECT vehicle_fueling_facility, vehicle_testing_facility, vehicle_washing_facility, + caltrans_district, dt, execution_ts FROM fct_stations_and_facilities_by_agency_and_facility_type diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_stations_by_mode_and_age.sql b/warehouse/models/mart/ntd_annual_reporting/fct_stations_by_mode_and_age.sql index 2fb15eb8f4..3b2874b941 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_stations_by_mode_and_age.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_stations_by_mode_and_age.sql @@ -3,9 +3,24 @@ WITH staging_stations_by_mode_and_age AS ( FROM {{ ref('stg_ntd__stations_by_mode_and_age') }} ), -fct_stations_by_mode_and_age AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_stations_by_mode_and_age AS ( + SELECT + staging_stations_by_mode_and_age.*, + dim_organizations.caltrans_district FROM staging_stations_by_mode_and_age + LEFT JOIN dim_organizations + ON CASE + WHEN staging_stations_by_mode_and_age.report_year = 2022 THEN + staging_stations_by_mode_and_age.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_stations_by_mode_and_age.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -34,6 +49,7 @@ SELECT total_facilities, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_stations_by_mode_and_age diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_agency.sql index bedea1d39f..32847c7592 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_track_and_roadway_by_agency AS ( FROM {{ ref('stg_ntd__track_and_roadway_by_agency') }} ), -fct_track_and_roadway_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_track_and_roadway_by_agency AS ( + SELECT + staging_track_and_roadway_by_agency.*, + dim_organizations.caltrans_district FROM staging_track_and_roadway_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_track_and_roadway_by_agency.report_year = 2022 THEN + staging_track_and_roadway_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_track_and_roadway_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -41,6 +56,7 @@ SELECT sum_slip_switch, sum_total_miles, sum_total_track_miles, + caltrans_district, dt, execution_ts FROM fct_track_and_roadway_by_agency diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_mode.sql b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_mode.sql index 14e25863d8..874fba4b55 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_mode.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_by_mode.sql @@ -3,9 +3,24 @@ WITH staging_track_and_roadway_by_mode AS ( FROM {{ ref('stg_ntd__track_and_roadway_by_mode') }} ), -fct_track_and_roadway_by_mode AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_track_and_roadway_by_mode AS ( + SELECT + staging_track_and_roadway_by_mode.*, + dim_organizations.caltrans_district FROM staging_track_and_roadway_by_mode + LEFT JOIN dim_organizations + ON CASE + WHEN staging_track_and_roadway_by_mode.report_year = 2022 THEN + staging_track_and_roadway_by_mode.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_track_and_roadway_by_mode.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -65,6 +80,7 @@ SELECT type_of_service, uace_code, uza_name, + caltrans_district, dt, execution_ts FROM fct_track_and_roadway_by_mode diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_guideway_age_distribution.sql b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_guideway_age_distribution.sql index 074f083aa1..be2736bdde 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_guideway_age_distribution.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_track_and_roadway_guideway_age_distribution.sql @@ -3,9 +3,63 @@ WITH staging_track_and_roadway_guideway_age_distribution AS ( FROM {{ ref('stg_ntd__track_and_roadway_guideway_age_distribution') }} ), -fct_track_and_roadway_guideway_age_distribution AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_track_and_roadway_guideway_age_distribution AS ( + SELECT + staging_track_and_roadway_guideway_age_distribution.*, + dim_organizations.caltrans_district FROM staging_track_and_roadway_guideway_age_distribution + LEFT JOIN dim_organizations + ON CASE + WHEN staging_track_and_roadway_guideway_age_distribution.report_year = 2022 THEN + staging_track_and_roadway_guideway_age_distribution.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_track_and_roadway_guideway_age_distribution.ntd_id = dim_organizations.ntd_id + END ) -SELECT * FROM fct_track_and_roadway_guideway_age_distribution +SELECT + _1940s, + _1940s_q, + _1950s, + _1950s_q, + _1960s, + _1960s_q, + _1970s, + _1970s_q, + _1980s, + _1980s_q, + _1990s, + _1990s_q, + _2000s, + _2000s_q, + _2010s, + _2010s_q, + _2020s, + _2020s_q, + agency, + agency_voms, + city, + guideway_element, + mode, + mode_name, + ntd_id, + organization_type, + pre1940s, + pre1940s_q, + primary_uza_population, + report_year, + reporter_type, + state, + type_of_service, + uace_code, + uza_name, + caltrans_district, + dt, + execution_ts +FROM fct_track_and_roadway_guideway_age_distribution diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_age_distribution.sql b/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_age_distribution.sql index 3699dbf25c..b555b2e57e 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_age_distribution.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_age_distribution.sql @@ -3,9 +3,24 @@ WITH staging_vehicles_age_distribution AS ( FROM {{ ref('stg_ntd__vehicles_age_distribution') }} ), -fct_vehicles_age_distribution AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_vehicles_age_distribution AS ( + SELECT + staging_vehicles_age_distribution.*, + dim_organizations.caltrans_district FROM staging_vehicles_age_distribution + LEFT JOIN dim_organizations + ON CASE + WHEN staging_vehicles_age_distribution.report_year = 2022 THEN + staging_vehicles_age_distribution.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_vehicles_age_distribution.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -43,6 +58,7 @@ SELECT uace_code, uza_name, vehicle_type, + caltrans_district, dt, execution_ts FROM fct_vehicles_age_distribution diff --git a/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_type_count_by_agency.sql b/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_type_count_by_agency.sql index 63e9632e02..a6609413ba 100644 --- a/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_type_count_by_agency.sql +++ b/warehouse/models/mart/ntd_annual_reporting/fct_vehicles_type_count_by_agency.sql @@ -3,9 +3,24 @@ WITH staging_vehicles_type_count_by_agency AS ( FROM {{ ref('stg_ntd__vehicles_type_count_by_agency') }} ), -fct_vehicles_type_count_by_agency AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_vehicles_type_count_by_agency AS ( + SELECT + staging_vehicles_type_count_by_agency.*, + dim_organizations.caltrans_district FROM staging_vehicles_type_count_by_agency + LEFT JOIN dim_organizations + ON CASE + WHEN staging_vehicles_type_count_by_agency.report_year = 2022 THEN + staging_vehicles_type_count_by_agency.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_vehicles_type_count_by_agency.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -105,6 +120,7 @@ SELECT vintage_historic_trolley, vintage_historic_trolley_1, vintage_historic_trolley_2, + caltrans_district, dt, execution_ts FROM fct_vehicles_type_count_by_agency diff --git a/warehouse/models/mart/ntd_safety_and_security/fct_fra_regulated_mode_major_security_events.sql b/warehouse/models/mart/ntd_safety_and_security/fct_fra_regulated_mode_major_security_events.sql index 8d8e306263..ded094573c 100644 --- a/warehouse/models/mart/ntd_safety_and_security/fct_fra_regulated_mode_major_security_events.sql +++ b/warehouse/models/mart/ntd_safety_and_security/fct_fra_regulated_mode_major_security_events.sql @@ -3,9 +3,24 @@ WITH staging_fra_regulated_mode_major_security_events AS ( FROM {{ ref('stg_ntd__fra_regulated_mode_major_security_events') }} ), -fct_fra_regulated_mode_major_security_events AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_fra_regulated_mode_major_security_events AS ( + SELECT + staging_fra_regulated_mode_major_security_events.*, + dim_organizations.caltrans_district FROM staging_fra_regulated_mode_major_security_events + LEFT JOIN dim_organizations + ON CASE + WHEN staging_fra_regulated_mode_major_security_events.year <= 2022 THEN + staging_fra_regulated_mode_major_security_events.ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_fra_regulated_mode_major_security_events.ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -98,6 +113,7 @@ SELECT pedestrian_not_in_crosswalk, number_of_derailed_cars, ntd_id, + caltrans_district, dt, execution_ts FROM fct_fra_regulated_mode_major_security_events diff --git a/warehouse/models/mart/ntd_safety_and_security/fct_major_safety_events.sql b/warehouse/models/mart/ntd_safety_and_security/fct_major_safety_events.sql index 1f9493207c..515628ca46 100644 --- a/warehouse/models/mart/ntd_safety_and_security/fct_major_safety_events.sql +++ b/warehouse/models/mart/ntd_safety_and_security/fct_major_safety_events.sql @@ -3,9 +3,24 @@ WITH staging_major_safety_events AS ( FROM {{ ref('stg_ntd__major_safety_events') }} ), -fct_major_safety_events AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_major_safety_events AS ( + SELECT + staging_major_safety_events.*, + dim_organizations.caltrans_district FROM staging_major_safety_events + LEFT JOIN dim_organizations + ON CASE + WHEN staging_major_safety_events.yr <= 2022 THEN + staging_major_safety_events.ntdid = dim_organizations.ntd_id_2022 + ELSE + staging_major_safety_events.ntdid = dim_organizations.ntd_id + END ) SELECT @@ -29,6 +44,7 @@ SELECT reportername, customer, ntdid, + caltrans_district, dt, execution_ts FROM fct_major_safety_events diff --git a/warehouse/models/mart/ntd_safety_and_security/fct_monthly_modal_time_series_safety_and_service.sql b/warehouse/models/mart/ntd_safety_and_security/fct_monthly_modal_time_series_safety_and_service.sql index ee9fc2ec08..aa46c45830 100644 --- a/warehouse/models/mart/ntd_safety_and_security/fct_monthly_modal_time_series_safety_and_service.sql +++ b/warehouse/models/mart/ntd_safety_and_security/fct_monthly_modal_time_series_safety_and_service.sql @@ -3,9 +3,24 @@ WITH staging_monthly_modal_time_series_safety_and_service AS ( FROM {{ ref('stg_ntd__monthly_modal_time_series_safety_and_service') }} ), -fct_monthly_modal_time_series_safety_and_service AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_monthly_modal_time_series_safety_and_service AS ( + SELECT + staging_monthly_modal_time_series_safety_and_service.*, + dim_organizations.caltrans_district FROM staging_monthly_modal_time_series_safety_and_service + LEFT JOIN dim_organizations + ON CASE + WHEN staging_monthly_modal_time_series_safety_and_service.year <= 2022 THEN + staging_monthly_modal_time_series_safety_and_service._5_digit_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_monthly_modal_time_series_safety_and_service._5_digit_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -82,6 +97,7 @@ SELECT total_other_injuries, other_fatalities, pedestrian_not_in_crosswalk, + caltrans_district, dt, execution_ts FROM fct_monthly_modal_time_series_safety_and_service diff --git a/warehouse/models/mart/ntd_safety_and_security/fct_nonmajor_safety_and_security_events.sql b/warehouse/models/mart/ntd_safety_and_security/fct_nonmajor_safety_and_security_events.sql index 5e5fab40d4..71b5e722c8 100644 --- a/warehouse/models/mart/ntd_safety_and_security/fct_nonmajor_safety_and_security_events.sql +++ b/warehouse/models/mart/ntd_safety_and_security/fct_nonmajor_safety_and_security_events.sql @@ -3,9 +3,24 @@ WITH staging_nonmajor_safety_and_security_events AS ( FROM {{ ref('stg_ntd__nonmajor_safety_and_security_events') }} ), -fct_nonmajor_safety_and_security_events AS ( +dim_organizations AS ( SELECT * + FROM {{ ref('dim_organizations') }} + WHERE _is_current +), + +fct_nonmajor_safety_and_security_events AS ( + SELECT + staging_nonmajor_safety_and_security_events.*, + dim_organizations.caltrans_district FROM staging_nonmajor_safety_and_security_events + LEFT JOIN dim_organizations + ON CASE + WHEN staging_nonmajor_safety_and_security_events.year <= 2022 THEN + staging_nonmajor_safety_and_security_events._5_digit_ntd_id = dim_organizations.ntd_id_2022 + ELSE + staging_nonmajor_safety_and_security_events._5_digit_ntd_id = dim_organizations.ntd_id + END ) SELECT @@ -127,6 +142,7 @@ SELECT number_of_transit_vehicles, year, uace_code, + caltrans_district, dt, execution_ts FROM fct_nonmajor_safety_and_security_events diff --git a/warehouse/models/staging/ntd_annual_reporting/stg_ntd__2023_contractual_relationships.sql b/warehouse/models/staging/ntd_annual_reporting/stg_ntd__2023_contractual_relationships.sql index e7a2a7fbdb..19b2c90bee 100644 --- a/warehouse/models/staging/ntd_annual_reporting/stg_ntd__2023_contractual_relationships.sql +++ b/warehouse/models/staging/ntd_annual_reporting/stg_ntd__2023_contractual_relationships.sql @@ -42,7 +42,7 @@ SELECT {{ trim_make_empty_string_null('reporting_module') }} AS reporting_module, {{ trim_make_empty_string_null('reporter_type') }} AS reporter_type, {{ trim_make_empty_string_null('other_public_assets_provided_desc') }} AS other_public_assets_provided_desc, - SAFE_CAST(ntd_id AS INTEGER) AS ntd_id, + SAFE_CAST(ntd_id AS STRING) AS ntd_id, dt, execution_ts FROM stg_ntd__2023_contractual_relationships diff --git a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__fra_regulated_mode_major_security_events.sql b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__fra_regulated_mode_major_security_events.sql index 3595e3fa38..70dec7f7a4 100644 --- a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__fra_regulated_mode_major_security_events.sql +++ b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__fra_regulated_mode_major_security_events.sql @@ -104,7 +104,7 @@ SELECT SAFE_CAST(other_fatalities AS INTEGER) AS other_fatalities, SAFE_CAST(pedestrian_not_in_crosswalk AS INTEGER) AS pedestrian_not_in_crosswalk, SAFE_CAST(number_of_derailed_cars AS NUMERIC) AS number_of_derailed_cars, - SAFE_CAST(ntd_id AS INTEGER) AS ntd_id, + SAFE_CAST(ntd_id AS STRING) AS ntd_id, dt, execution_ts FROM stg_ntd__fra_regulated_mode_major_security_events diff --git a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__major_safety_events.sql b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__major_safety_events.sql index 3c71353e8d..b06e7f2fe5 100644 --- a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__major_safety_events.sql +++ b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__major_safety_events.sql @@ -35,7 +35,7 @@ SELECT {{ trim_make_empty_string_null('typeofservicecd') }} AS typeofservicecd, {{ trim_make_empty_string_null('reportername') }} AS reportername, SAFE_CAST(customer AS INTEGER) AS customer, - SAFE_CAST(ntdid AS INTEGER) AS ntdid, + SAFE_CAST(ntdid AS STRING) AS ntdid, dt, execution_ts FROM stg_ntd__major_safety_events diff --git a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__monthly_modal_time_series_safety_and_service.sql b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__monthly_modal_time_series_safety_and_service.sql index 3d762a01b9..d34ba6e875 100644 --- a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__monthly_modal_time_series_safety_and_service.sql +++ b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__monthly_modal_time_series_safety_and_service.sql @@ -85,7 +85,7 @@ SELECT SAFE_CAST(pedestrian_crossing_tracks_1 AS INTEGER) AS pedestrian_crossing_tracks_1, SAFE_CAST(primary_uza_sq_miles AS NUMERIC) AS primary_uza_sq_miles, {{ trim_make_empty_string_null('primary_uza_name') }} AS primary_uza_name, - SAFE_CAST(_5_digit_ntd_id AS INTEGER) AS _5_digit_ntd_id, + SAFE_CAST(_5_digit_ntd_id AS STRING) AS _5_digit_ntd_id, SAFE_CAST(total_other_injuries AS INTEGER) AS total_other_injuries, SAFE_CAST(other_fatalities AS INTEGER) AS other_fatalities, SAFE_CAST(pedestrian_not_in_crosswalk AS INTEGER) AS pedestrian_not_in_crosswalk, diff --git a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__nonmajor_safety_and_security_events.sql b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__nonmajor_safety_and_security_events.sql index 4a6cf7a26f..c9e3dd1ee7 100644 --- a/warehouse/models/staging/ntd_safety_and_security/stg_ntd__nonmajor_safety_and_security_events.sql +++ b/warehouse/models/staging/ntd_safety_and_security/stg_ntd__nonmajor_safety_and_security_events.sql @@ -57,7 +57,7 @@ SELECT SAFE_CAST(pederstiran_in_crosswalk AS INTEGER) AS pederstiran_in_crosswalk, SAFE_CAST(__computed_region_8fe2_rd7y AS NUMERIC) AS __computed_region_8fe2_rd7y, SAFE_CAST(bicyclist_injuries AS INTEGER) AS bicyclist_injuries, - SAFE_CAST(_5_digit_ntd_id AS INTEGER) AS _5_digit_ntd_id, + SAFE_CAST(_5_digit_ntd_id AS STRING) AS _5_digit_ntd_id, SAFE_CAST(transit_employee_serious AS INTEGER) AS transit_employee_serious, SAFE_CAST(transit_employee_injuries AS INTEGER) AS transit_employee_injuries, SAFE_CAST(trespasser_serious_injuries_subtotal_ AS INTEGER) AS trespasser_serious_injuries_subtotal_,