Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ok 602 pub kerroksen korjauksia #77

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions dbt/models/int/int_organisaatio.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
)
}}

with organisaatio as (
with organisaatio_raw as (
select
*,
row_number() over (partition by organisaatio_oid order by muokattu desc) as rownr
from {{ ref('dw_organisaatio_organisaatio') }}
),

organisaatio as not materialized (
select * from organisaatio_raw where rownr = 1
),

ylempi_toimipiste as (
select
organisaatio_oid,
nimi_fi,
nimi_sv
from organisaatio
where organisaatiotyypit @> '["organisaatiotyyppi_03"]'
),


kunta as (
select * from {{ ref('int_koodisto_kunta') }} where viimeisin_versio
),
Expand All @@ -23,36 +37,49 @@ organisaatiotyyppi as (
select * from {{ ref('int_organisaatio_organisaatiotyyppi') }}
),

raw as (
int as (
select
organisaatio_oid,
coalesce(nimi_fi, nimi_sv) as nimi_fi_new,
coalesce(nimi_sv, nimi_fi) as nimi_sv_new,
coalesce(nimi_fi, nimi_sv) as nimi_en_new,
ylempi_organisaatio,
sijaintikunta,
tila,
opetuskielet,
organisaatiotyypit
from organisaatio
where rownr = 1
org1.organisaatio_oid,
coalesce(org1.nimi_fi, org1.nimi_sv) as nimi_fi_new,
coalesce(org1.nimi_sv, org1.nimi_fi) as nimi_sv_new,
coalesce(org1.nimi_fi, org1.nimi_sv) as nimi_en_new,
coalesce(ylto.nimi_fi, ylto.nimi_sv) as nimi_fi_new_ylempi,
coalesce(ylto.nimi_sv, ylto.nimi_fi) as nimi_sv_new_ylempi,
coalesce(ylto.nimi_fi, ylto.nimi_sv) as nimi_en_new_ylempi,
org1.ylempi_organisaatio,
org1.sijaintikunta,
org1.tila,
org1.opetuskielet,
org1.organisaatiotyypit
from organisaatio as org1
left join ylempi_toimipiste as ylto on org1.ylempi_organisaatio = ylto.organisaatio_oid
),

final as (
select
raw1.organisaatio_oid,
jsonb_build_object(
'en', raw1.nimi_en_new,
'sv', raw1.nimi_sv_new,
'fi', raw1.nimi_fi_new
) as organisaatio_nimi,
case
when nimi_fi_new_ylempi is not null
then
jsonb_build_object(
'en', nimi_en_new_ylempi || ', ' || nimi_en_new,
'sv', nimi_sv_new_ylempi || ', ' || nimi_sv_new,
'fi', nimi_fi_new_ylempi || ', ' || nimi_fi_new
)
else
jsonb_build_object(
'en', nimi_en_new,
'sv', nimi_sv_new,
'fi', nimi_fi_new
)
end as organisaatio_nimi,
raw1.ylempi_organisaatio,
raw1.sijaintikunta,
kunt.koodinimi as sijaintikunta_nimi,
raw1.opetuskielet,
orgt.organisaatiotyypit,
raw1.tila
from raw as raw1
from int as raw1
left join kunta as kunt on raw1.sijaintikunta = kunt.koodiuri
left join organisaatiotyyppi as orgt on raw1.organisaatio_oid = orgt.organisaatio_oid
)
Expand Down