Skip to content

Commit

Permalink
pull new intermediate tables through to mart tables
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-costanzo committed Jan 30, 2025
1 parent 743459f commit 30e0270
Show file tree
Hide file tree
Showing 52 changed files with 1,766 additions and 980 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__capital_expenditures_time_series__facilities"),
exclude=[
"_2023_mode_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"mode",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="facilities",
)
}}
),

int_ntd__capital_expenditures_time_series_facilities AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
mode,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
facilities,
_2023_mode_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__capital_expenditures_time_series_facilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__capital_expenditures_time_series__other"),
exclude=[
"_2023_mode_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"mode",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="other",
)
}}
),

int_ntd__capital_expenditures_time_series_other AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
mode,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
other,
_2023_mode_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__capital_expenditures_time_series_other
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__capital_expenditures_time_series__rolling_stock"),
exclude=[
"_2023_mode_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"mode",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="rolling_stock",
)
}}
),

int_ntd__capital_expenditures_time_series_rolling_stock AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
mode,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
rolling_stock,
_2023_mode_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__capital_expenditures_time_series_rolling_stock
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__capital_expenditures_time_series__total"),
exclude=[
"_2023_mode_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"mode",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="total",
)
}}
),

int_ntd__capital_expenditures_time_series_total AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
mode,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
total,
_2023_mode_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__capital_expenditures_time_series_total
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__operating_and_capital_funding_time_series__capital_federal"),
exclude=[
"_2023_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"primary_uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="capital_federal",
)
}}
),

int_ntd__operating_and_capital_funding_time_series_capital_federal AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
primary_uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
capital_federal,
_2023_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__operating_and_capital_funding_time_series_capital_federal
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{ config(materialized="table") }}

WITH
source_pivoted AS (
{{
dbt_utils.unpivot(
cast_to="int",
relation=ref("stg_ntd__operating_and_capital_funding_time_series__capital_local"),
exclude=[
"_2023_status",
"agency_name",
"agency_status",
"census_year",
"city",
"last_report_year",
"legacy_ntd_id",
"ntd_id",
"reporter_type",
"reporting_module",
"state",
"uace_code",
"uza_area_sq_miles",
"primary_uza_name",
"uza_population",
"dt",
"execution_ts"
],
field_name="year",
value_name="capital_local",
)
}}
),

int_ntd__operating_and_capital_funding_time_series_capital_local AS (
SELECT
agency_name,
agency_status,
census_year,
city,
last_report_year,
legacy_ntd_id,
format("%05d", cast(cast(ntd_id AS NUMERIC) AS INT64)) AS ntd_id,
reporter_type,
reporting_module,
state,
uace_code,
uza_area_sq_miles,
primary_uza_name,
uza_population,
split(year, '_')[offset(1)] AS year,
capital_local,
_2023_status,
dt,
execution_ts
FROM source_pivoted
)

SELECT * FROM int_ntd__operating_and_capital_funding_time_series_capital_local
Loading

0 comments on commit 30e0270

Please sign in to comment.