-
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.
- Loading branch information
laurinehu
committed
Dec 17, 2024
1 parent
f776c4a
commit 8833c1e
Showing
6 changed files
with
60 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
5 changes: 2 additions & 3 deletions
5
dbt/models/marts/daily/candidatures_candidats_recherche_active.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
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
44 changes: 44 additions & 0 deletions
44
dbt/models/marts/weekly/candidats_recherche_active_histo.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,44 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key=['id', 'semaine_valide'], | ||
post_hook=""" | ||
DELETE FROM {{ this }} | ||
WHERE date_derniere_candidature_acceptee is not null and delai_premiere_candidature > 30 | ||
""" | ||
) | ||
}} | ||
|
||
-- recover last known date in the table to increment for new period | ||
with last_known_date as ( | ||
select | ||
max(date_trunc('week', dbt_valid_to)) as lkd | ||
from {{ ref('candidats_recherche_active_snapshot') }} | ||
) | ||
|
||
select | ||
{{ pilo_star(ref('candidats_recherche_active_snapshot'), except=["dbt_valid_from", "dbt_valid_to"]) }}, | ||
date_trunc('week', week_series) as semaine_valide | ||
from | ||
{{ ref('candidats_recherche_active_snapshot') }} | ||
cross join | ||
last_known_date | ||
cross join | ||
generate_series( | ||
date_trunc('week', dbt_valid_from), | ||
-- when dbt_valid_to is empty, state is still the same today | ||
-- so we compute row for each week from valid_to to today | ||
coalesce(date_trunc('week', dbt_valid_to), last_known_date.lkd), | ||
interval '1 week' | ||
) as week_series | ||
|
||
{% if is_incremental() %} | ||
|
||
-- we only update rows that have changed | ||
-- the previous state is no longer current if : | ||
-- 1: dbt_valid_from is bigger than last week date (this line is the new state) // dbt_valid_from is bigger than the last known date | ||
-- 2: dbt_valid_to is bigger than last week date (this line is the last state that is now finished) // dbt_valid | ||
where dbt_valid_from >= last_known_date.lkd | ||
or dbt_valid_to >= last_known_date.lkd | ||
|
||
{% endif %} |
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,4 @@ | ||
-- if there is a date_derniere_candidature_acceptee, the candidate is not in the file active | ||
select * | ||
from candidats_recherche_active | ||
where file_active_30_jours = true and date_derniere_candidature_acceptee is not null |