Skip to content

Commit

Permalink
Add staging for mastr hydro #9
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianK13 committed Dec 6, 2023
1 parent a598087 commit 69f8466
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
50 changes: 50 additions & 0 deletions dbt/models/staging/mastr/stg_mastr__hydro.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{
config(
materialized = 'table',
indexes=[
{'columns': ['coordinate'], 'type': 'gist'}
]
)
}}

with source as (
select * from {{ source('raw_mastr', 'hydro_extended') }}
),

final as (

select
--general
"EinheitMastrNummer" as mastr_id,
"EinheitBetriebsstatus" as operating_status,
"NetzbetreiberpruefungStatus" as grid_operator_inspection,
--dates
CASE
WHEN "Inbetriebnahmedatum" IS NOT NULL OR "GeplantesInbetriebnahmedatum" IS NOT NULL THEN
concat(
date_part('year', "Inbetriebnahmedatum"),
date_part('year', "GeplantesInbetriebnahmedatum")
)::integer
ELSE
NULL
END as installation_year,
"Inbetriebnahmedatum" as commissioning_date,
"GeplantesInbetriebnahmedatum" as planned_commissioning_date,
"DatumDownload" as download_date,
--technical
"ArtDerWasserkraftanlage" as plant_type,
"ArtDesZuflusses" as type_of_inflow,
"Nettonennleistung" as power,
--owner
"AnlagenbetreiberMastrNummer" as unit_owner_mastr_id,
--location
"Gemeindeschluessel" as municipality_id,
"Gemeinde" as municipality,
left("Gemeindeschluessel", 5) as district_id,
"Landkreis" as district,
"Postleitzahl" as zip_code,
st_setsrid(st_point("Laengengrad", "Breitengrad"), 4326) as coordinate
from source
)

select * from final
66 changes: 66 additions & 0 deletions dbt/models/staging/mastr/stg_mastr__hydro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: 2
models:
- name: stg_mastr__hydro
columns:
- name: mastr_id
description: ''
data_type: character varying
tests:
- unique
- not_null
- expect_column_values_to_match_regex:
name: regex_stg_mastr__hydro_mastr_id
regex: "^[A-Z]{3}\\d{12}$"
- name: operating_status
description: ''
data_type: character varying
tests:
- not_null
- accepted_values:
name: accepted_values_stg_mastr__hydro_operating_status
values: ['In Betrieb', 'In Planung', 'Endgültig stillgelegt', 'Vorübergehend stillgelegt']
- name: grid_operator_inspection
description: ''
data_type: character varying
- name: installation_year
description: ''
data_type: integer
- name: commissioning_date
description: ''
data_type: date
- name: planned_commissioning_date
description: ''
data_type: date
- name: download_date
description: ''
data_type: date
- name: plant_type
description: ''
data_type: character varying
- name: type_of_inflow
description: ''
data_type: character varying
- name: power
description: ''
data_type: double precision
- name: unit_owner_mastr_id
description: ''
data_type: character varying
- name: municipality_id
description: ''
data_type: character varying
- name: municipality
description: ''
data_type: character varying
- name: district_id
description: ''
data_type: text
- name: district
description: ''
data_type: character varying
- name: zip_code
description: ''
data_type: character varying
- name: coordinate
description: ''
data_type: USER-DEFINED

0 comments on commit 69f8466

Please sign in to comment.