-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a598087
commit 69f8466
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |