-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: add mhcil transformations in dbt to datamarts (et/somenergia-jar…
…diner!38) Merge branch 'feature/mhcil-transformations-dbt-to-dms' into 'main'
- Loading branch information
Showing
13 changed files
with
175 additions
and
11 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
9 changes: 0 additions & 9 deletions
9
dbt_jardiner/models/jardiner/intermediate/simel/_simel__sources.yaml
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...diner/models/jardiner/intermediate/simel/int_simel_mhcil__pen_best_ranked_incremental.sql
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,47 @@ | ||
{{ | ||
config( | ||
enabled=false, | ||
materialized="incremental", | ||
incremental_strategy="append", | ||
unique_key="surrogate_key", | ||
) | ||
}} | ||
|
||
|
||
{% if not is_incremental() %} | ||
|
||
select {{ dbt_utils.star(from=ref("int_simel_mhcil__pen_best_ranked_view")) }} | ||
from {{ ref("int_simel_mhcil__pen_best_ranked_view") }} | ||
|
||
{% else %} | ||
|
||
with existing as ( | ||
select | ||
surrogate_key, | ||
total_rank, | ||
ranked_at | ||
from {{ this }} | ||
), | ||
|
||
incoming as ( | ||
select {{ dbt_utils.star(from=ref("int_simel_mhcil__pen_best_ranked_view")) }} | ||
from {{ ref("int_simel_mhcil__pen_best_ranked_view") }} | ||
), | ||
|
||
new_rankings as ( | ||
select | ||
incoming.surrogate_key, | ||
incoming.total_rank, | ||
incoming.ranked_at | ||
from existing | ||
left join incoming | ||
on existing.surrogate_key = incoming.surrogate_key | ||
where | ||
existing.total_rank < incoming.total_rank | ||
and existing.ranked_at < incoming.ranked_at | ||
) | ||
|
||
select * | ||
from new_rankings | ||
|
||
{% endif %} |
28 changes: 28 additions & 0 deletions
28
dbt_jardiner/models/jardiner/intermediate/simel/int_simel_mhcil__pen_best_ranked_view.sql
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,28 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with ranked as ( | ||
select | ||
*, | ||
extract(epoch from start_at) + file_version + firmeza_rank + maturity_rank as total_rank | ||
from {{ ref("int_simel_mhcil__pen_extended") }} | ||
), | ||
|
||
ordered as ( | ||
select | ||
*, | ||
row_number() over ( | ||
partition by cil, start_at | ||
order by total_rank | ||
) as row_order | ||
from ranked | ||
), | ||
|
||
best_ranked as ( | ||
select | ||
*, | ||
now() as ranked_at, | ||
{{ dbt_utils.generate_surrogate_key(["cil", "start_at"]) }} as surrogate_key | ||
from ordered where row_order = 1 | ||
) | ||
|
||
select * from best_ranked |
59 changes: 59 additions & 0 deletions
59
dbt_jardiner/models/jardiner/intermediate/simel/int_simel_mhcil__pen_extended.sql
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,59 @@ | ||
{{ config(materialized="view") }} | ||
|
||
|
||
with timestamp_crafted as ( | ||
select | ||
*, | ||
make_timestamp( | ||
cast("year" as int), cast("month" as int), cast("day" as int), cast("hour" as int), 0, 0 | ||
) as measurement_timestamp | ||
from {{ ref("raw_airbyte_simel__mhcil_pen") }} | ||
), | ||
|
||
timestamp_localized as ( | ||
select | ||
*, | ||
case | ||
when is_summer | ||
then measurement_timestamp at time zone 'CEST' | ||
else measurement_timestamp at time zone 'CET' | ||
end as measurement_timestamptz | ||
from timestamp_crafted | ||
), | ||
|
||
extended_mhcil as ( | ||
select | ||
cil, | ||
measurement_timestamptz as start_at, | ||
hour, | ||
is_summer, | ||
energy_kwh, | ||
reactive_energy_2_kvarh, | ||
reactive_energy_3_kvarh, | ||
measurement_type, | ||
_ab_source_file_url as file_name, | ||
_airbyte_normalized_at as ingested_at, | ||
cast(_ab_source_file_last_modified as timestamptz) as file_last_modified_at, | ||
cast(split_part(_ab_source_file_url, '.', 2) as int) as file_version, | ||
cast(split_part(_ab_source_file_url, '_', 1) as varchar(5)) as file_type, -- fecha a la que corresponden los datos | ||
cast(split_part(_ab_source_file_url, '_', 2) as varchar(2)) as release_period, -- tipo de fichero según simel | ||
cast(split_part(_ab_source_file_url, '_', 3) as varchar(4)) as member_code, -- periodo de publicación | ||
cast(split_part(_ab_source_file_url, '_', 4) as varchar(2)) as file_receiver_type, -- código de participante | ||
to_date(right(split_part(_ab_source_file_url, '.', 1), 8), 'YYYYMMDD') as file_date -- tipo de receptor de fichero | ||
from timestamp_localized | ||
), | ||
|
||
ranked as ( | ||
select | ||
exmhcil.*, | ||
cast(firmeza_ranking.rank as int) as firmeza_rank, | ||
cast(maturity_ranking.rank as int) as maturity_rank | ||
from extended_mhcil as exmhcil | ||
left join {{ ref("seed_simel_mhcil_rankings__firmeza") }} as firmeza_ranking | ||
on exmhcil.measurement_type = firmeza_ranking.name | ||
left join {{ ref("seed_simel_mhcil_rankings__maturity") }} as maturity_ranking | ||
on exmhcil.release_period = maturity_ranking.name | ||
) | ||
|
||
select * | ||
from ranked |
Empty file.
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
10 changes: 10 additions & 0 deletions
10
dbt_jardiner/models/jardiner/raw/simel/_simel__sources.yaml
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,10 @@ | ||
--- | ||
version: 2 | ||
|
||
sources: | ||
- name: airbyte_simel | ||
schema: airbyte_imported | ||
tables: | ||
- name: simel_mhcil_nas | ||
description: Dades des de SIMEL sincronitzades des de minio.somenergia.coop. Només conté dades de sistema peninsular (PEN) | ||
|
File renamed without changes.
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,9 @@ | ||
version: 2 | ||
|
||
seeds: | ||
- name: seed_simel_file_rankings__firmeza | ||
description: | | ||
Seed que genera un ranking dels fitxers segons la seva firmeza i el document SIMEL_Ficheros_Intercambio_Informacion_v40_Oct2022.pdf | ||
- name: seed_simel_file_rankings__maturity | ||
description: | | ||
Seed que genera un ranking dels fitxers segons la seva maduresa i el document SIMEL_Ficheros_Intercambio_Informacion_v40_Oct2022.pdf |
5 changes: 5 additions & 0 deletions
5
dbt_jardiner/seeds/jardiner/seed_simel_mhcil_rankings__firmeza.csv
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,5 @@ | ||
id,name,rank,description | ||
1,R,4,Real con reparto por potencia | ||
2,L,3,Estimación con reparto por potencia | ||
3,E,2,Real con reparto por energía individualizada de CIL | ||
4,M,1,Estimación con reparto por energía individualizada de CI |
6 changes: 6 additions & 0 deletions
6
dbt_jardiner/seeds/jardiner/seed_simel_mhcil_rankings__maturity.csv
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,6 @@ | ||
id,name,rank,description | ||
1,HD,1,valores de cierre diario | ||
2,H2,2,valores de cierre de mes m-1 | ||
3,H3,3,valores de cierre de mes m-3 | ||
4,HP,4,valores de cierre provisional | ||
5,HC,5,valores de cierre definitivo |
2 changes: 1 addition & 1 deletion
2
dbt_jardiner/tests/dset/test_dset_signals_receiver_last_hour.sql
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