-
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 device_parent_uuid into pipe and filters out deactivated sig…
…nals (et/somenergia-jardiner!120) Closes #96 Merge branch 'fix/let-snapshot-add-new-columns' into 'main'
- Loading branch information
Showing
13 changed files
with
134 additions
and
103 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
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
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
61 changes: 31 additions & 30 deletions
61
...r/models/jardiner/intermediate/dset/int_dset_last_signal__from_latest_batch_dset_last.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 |
---|---|---|
@@ -1,36 +1,37 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with last_dset_batch as ( | ||
select | ||
case | ||
when signal_uuid ~ e'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' then signal_uuid::uuid -- noqa: LT01 | ||
end as signal_uuid, | ||
signal_uuid as signal_uuid_raw, | ||
{{ dbt_utils.star(from=ref("raw_dset_responses__last_signal_reading"), except=['signal_uuid']) }} | ||
from {{ ref("raw_dset_responses__last_signal_reading") }} | ||
select | ||
case | ||
when signal_uuid ~ e'^[[:xdigit:]]{8}-([[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$' then signal_uuid::uuid -- noqa: LT01 | ||
end as signal_uuid, | ||
signal_uuid as signal_uuid_raw, | ||
{{ dbt_utils.star(from=ref("raw_dset_responses__last_signal_reading"), except=['signal_uuid']) }} | ||
from {{ ref("raw_dset_responses__last_signal_reading") }} | ||
) | ||
select | ||
dset.signal_last_ts, | ||
dset.signal_last_value, | ||
dset.group_name as dset_plant_name, | ||
plants.plant_name, | ||
dset.queried_at, | ||
metadata.signal_name, | ||
metadata.metric_name, | ||
metadata.device_name, | ||
metadata.device_type, | ||
metadata.plant_uuid, | ||
metadata.device_uuid, | ||
metadata.device_parent, | ||
metadata.signal_uuid, | ||
dset.signal_id, | ||
dset.signal_tz, | ||
dset.signal_code, | ||
dset.signal_type, | ||
dset.signal_unit | ||
dset.signal_last_ts, | ||
dset.signal_last_value, | ||
dset.group_name as dset_plant_name, | ||
plants.plant_name, | ||
dset.queried_at, | ||
metadata.signal_name, | ||
metadata.metric_name, | ||
metadata.device_name, | ||
metadata.device_type, | ||
metadata.plant_uuid, | ||
metadata.device_uuid, | ||
metadata.device_parent, | ||
metadata.device_parent_uuid, | ||
metadata.signal_uuid, | ||
dset.signal_id, | ||
dset.signal_tz, | ||
dset.signal_code, | ||
dset.signal_type, | ||
dset.signal_unit | ||
from last_dset_batch as dset | ||
full outer join | ||
{{ ref("raw_gestio_actius__signal_denormalized") }} as metadata | ||
using (signal_uuid) | ||
left join {{ ref("int_gda_plants__plants_catalog") }} as plants | ||
using (plant_uuid) | ||
full outer join | ||
{{ ref("raw_gestio_actius__signal_denormalized") }} as metadata | ||
using (signal_uuid) | ||
left join {{ ref("int_gda_plants__plants_catalog") }} as plants | ||
using (plant_uuid) |
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
2 changes: 1 addition & 1 deletion
2
...dels/jardiner/intermediate/gestio_actius/int_signal_device_relation__distinct_devices.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{{ config(materialized="table") }} | ||
|
||
select distinct plant_name, plant_uuid, device_name, device_uuid, device_type, device_parent | ||
select distinct plant_name, plant_uuid, device_name, device_uuid, device_type, device_parent, device_parent_uuid | ||
from {{ ref('raw_gestio_actius__signal_denormalized') }} | ||
order by plant_name, device_name |
33 changes: 17 additions & 16 deletions
33
dbt_jardiner/models/jardiner/marts/dm_dset_last_reading__from_signal_last_ts.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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
{{ config(materialized="view") }} | ||
|
||
select | ||
plant_name as nom_planta, | ||
dset_plant_name as nom_planta_dset, | ||
signal_last_ts as ultim_ts, | ||
signal_last_value as ultim_valor, | ||
queried_at as peticionat_a, | ||
signal_name as nom_senyal, | ||
metric_name as nom_metrica, | ||
signal_unit as unitat, | ||
device_name as nom_aparell, | ||
device_type as tipus_aparell, | ||
device_parent as aparell_pare, | ||
signal_uuid as uuid_senyal, | ||
signal_id as id_senyal_dset, | ||
signal_code as codi_senyal_dset, | ||
signal_type as tipus_senyal | ||
from {{ ref("int_dset_last_signal__from_latest_batch_dset_last") }} | ||
plant_name as nom_planta, | ||
dset_plant_name as nom_planta_dset, | ||
signal_last_ts as ultim_ts, | ||
signal_last_value as ultim_valor, | ||
queried_at as peticionat_a, | ||
signal_name as nom_senyal, | ||
metric_name as nom_metrica, | ||
signal_unit as unitat, | ||
device_name as nom_aparell, | ||
device_type as tipus_aparell, | ||
device_parent as aparell_pare, | ||
device_parent_uuid as uuid_aparell_pare, | ||
signal_uuid as uuid_senyal, | ||
signal_id as id_senyal_dset, | ||
signal_code as codi_senyal_dset, | ||
signal_type as tipus_senyal | ||
from {{ ref("int_dset_last_signal__from_latest_batch_dset_last") }} |
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
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
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
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
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
42 changes: 21 additions & 21 deletions
42
dbt_jardiner/tests/dset/test_repeated_device_uuid_errors.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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
-- tests pairs device_uuid, plant, device, device_type, device_parent as unique | ||
with | ||
unique_device_per_plant as ( | ||
select distinct device_uuid, plant_uuid, plant_name, device_name, device_type, device_parent | ||
from {{ ref("raw_gestio_actius__signal_denormalized") }} | ||
order by plant_name, device_name | ||
), | ||
unique_device_per_plant as ( | ||
select distinct device_uuid, plant_uuid, plant_name, device_name, device_type, device_parent, device_parent_uuid | ||
from {{ ref("raw_gestio_actius__signal_denormalized") }} | ||
order by plant_name, device_name | ||
), | ||
|
||
duplicated_devices as ( | ||
select udpp.device_uuid, count(*) as n_duplicates | ||
from unique_device_per_plant as udpp | ||
group by udpp.device_uuid | ||
having count(*) > 1 | ||
), | ||
duplicated_devices as ( | ||
select udpp.device_uuid, count(*) as n_duplicates | ||
from unique_device_per_plant as udpp | ||
group by udpp.device_uuid | ||
having count(*) > 1 | ||
), | ||
|
||
joined as ( | ||
select expected.*, duplicated_devices.n_duplicates | ||
from {{ ref("raw_gestio_actius__signal_denormalized") }} as expected | ||
left join duplicated_devices on expected.device_uuid = duplicated_devices.device_uuid | ||
), | ||
joined as ( | ||
select expected.*, duplicated_devices.n_duplicates | ||
from {{ ref("raw_gestio_actius__signal_denormalized") }} as expected | ||
left join duplicated_devices on expected.device_uuid = duplicated_devices.device_uuid | ||
), | ||
|
||
filtered as ( | ||
select * | ||
from joined | ||
where n_duplicates is not null | ||
) | ||
filtered as ( | ||
select * | ||
from joined | ||
where n_duplicates is not null | ||
) | ||
|
||
select * from filtered |