Skip to content

Commit

Permalink
Muutettu dw_onr_henkilo tauluksi jotta saadaan parempi suorituskyky
Browse files Browse the repository at this point in the history
  • Loading branch information
Matz Rasmus committed Jan 7, 2025
1 parent 6ad8e3d commit 724455a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dbt/macros/helpers/dw_end.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
{% set query = 'CREATE TABLE if not exists raw.completed_dbt_runs (model text NULL, raw_table text NULL, start_time timestamptz NULL, "execute" bool NULL);' %}
{% do run_query(query) %}

with data as (
with raw as (
select
model,
replace(regexp_replace(split_part(model, '.', 3),'stg_',''),'"','') as raw_table,
start_time
from raw.dbt_runs dr
where model = replace ('{{ this }}','dw','stg')
),

data as (
select
model,
raw_table,
case when raw_table = 'onr_henkilo' then start_time - interval '1 hour' else start_time end as start_time
from raw
)


merge into raw.completed_dbt_runs as t
using data as s
on t.model = s.model
Expand Down
31 changes: 31 additions & 0 deletions dbt/models/dw/yleiskayttoiset/dw_onr_henkilo.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
{#
{%- set stage_model = ref('stg_onr_henkilo') -%}
{%- set key_columns_list = ['henkilo_oid'] -%}

{{ generate_dw_model_muokattu(stage_model, key_columns_list) }}

#}

{{
config(
materialized = 'table',
indexes = [
{'columns': ['henkilo_oid']}
]
)
}}

with raw as (
select
*,
row_number() over (partition by henkilo_oid order by dw_metadata_stg_stored_at desc) as rownr
from {{ ref('stg_onr_henkilo') }}
),

final as (
select
{{ dbt_utils.star(from=ref('stg_onr_henkilo')) }},
current_timestamp as dw_metadata_dw_stored_at
from raw
where rownr =1
)

select * from final


0 comments on commit 724455a

Please sign in to comment.