Skip to content

Commit

Permalink
Remake dim_monthly_ntd_ridership_with_adjustments to
Browse files Browse the repository at this point in the history
dim_monthly_ridership_with_adjustments (removed _ntd_).

- Format SQL file and reorder columns
- Remove irrelevant year column
- Rename columns to follow the same pattern as 
  the other new NTD models
- Add surrogate key

[#3519]
  • Loading branch information
erikamov committed Nov 16, 2024
1 parent e2fc280 commit 1e66b03
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e66b03

Please sign in to comment.