diff --git a/dbt/models/int/int_yleiskayttoiset/int_organisaatio_rakenne.sql b/dbt/models/int/int_yleiskayttoiset/int_organisaatio_rakenne.sql new file mode 100644 index 0000000..7c10f83 --- /dev/null +++ b/dbt/models/int/int_yleiskayttoiset/int_organisaatio_rakenne.sql @@ -0,0 +1,32 @@ +{{ + config( + materialized = 'table', + indexes = [ + {'columns':['parent_oid']} + ] + ) +}} + +with recursive organisaatio as ( + select * from {{ ref('int_organisaatio') }} +), + +org (parent_oid, child_oid) as ( + select + ylempi_organisaatio as parent_oid, + organisaatio_oid as child_oid + from organisaatio + + union all + + select + orga.parent_oid, + org2.organisaatio_oid as child_oid + from organisaatio as org2 + inner join org as orga on orga.child_oid = org2.ylempi_organisaatio +) + +select + parent_oid, + child_oid +from org diff --git a/dbt/models/pub/_pub.yml b/dbt/models/pub/_pub.yml index 08e5167..9b4b164 100644 --- a/dbt/models/pub/_pub.yml +++ b/dbt/models/pub/_pub.yml @@ -364,3 +364,32 @@ models: - name: kansalaisuusluokka description: "Kenttä kansalaisuuden filtteröintiin. Arvot: 1 = Suomi, 2 = EU/ETA, 3 = muut" data_type: integer + - name: pub_dim_organisaatio + description: Tämä taului sisältää organisaation tiedot + columns: + - name: organisaatio_oid + data_type: text + description: Organisaation oid + data_tests: + - dbt_constraints.primary_key + - name: organisaatio_nimi + description: Organisaation lokalisoidut nimet + data_type: jsonb + - name: sijaintikunta + data_type: text + - name: sijaintikunta_nimi + data_type: jsonb + - name: opetuskielet + data_type: jsonb + - name: organisaatiotyypit + data_type: jsonb + - name: tila + data_type: text + - name: pub_dim_organisaatio_rakenne + description: + Tämä taulu sisältää kaikki organisaatiot, ja kaikki hierarkiassa niiden alla olevat organisaatiot riippumatta tasosta. + columns: + - name: parent_oid + data_type: text + - name: child_oid + data_type: text diff --git a/dbt/models/pub/pub_dim_organisaatio.sql b/dbt/models/pub/pub_dim_organisaatio.sql new file mode 100644 index 0000000..fed2b56 --- /dev/null +++ b/dbt/models/pub/pub_dim_organisaatio.sql @@ -0,0 +1,26 @@ +{{ + config( + materialized = 'table', + indexes = [ + {'columns':['organisaatio_oid']} + ] + ) +}} + +with source as ( + select * from {{ ref('int_organisaatio') }} +), + +final as ( + select + organisaatio_oid, + organisaatio_nimi, + sijaintikunta, + sijaintikunta_nimi, + opetuskielet, + organisaatiotyypit, + tila + from source +) + +select * from final \ No newline at end of file diff --git a/dbt/models/pub/pub_dim_organisaatio_rakenne.sql b/dbt/models/pub/pub_dim_organisaatio_rakenne.sql new file mode 100644 index 0000000..b922a36 --- /dev/null +++ b/dbt/models/pub/pub_dim_organisaatio_rakenne.sql @@ -0,0 +1,17 @@ +{{ + config( + materialized = 'table', + indexes = [ + {'columns':['parent_oid']} + ] + ) +}} + +with source as ( + select * from {{ ref('int_organisaatio_rakenne') }} +) + +select + parent_oid, + child_oid +from source \ No newline at end of file