Skip to content

Commit

Permalink
Merge pull request #538 from basedosdados/staging/fix-sia-incremental
Browse files Browse the repository at this point in the history
[fix-sia] producao_ambulatorial
  • Loading branch information
folhesgabriel authored Apr 9, 2024
2 parents 6e84923 + 405a234 commit 6eb1e78
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"range": {"start": 2005, "end": 2024, "interval": 1},
},
cluster_by=["mes", "sigla_uf"],
pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}",
post_hook=[
'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:[email protected]", "group:[email protected]") FILTER USING (True)',
],
)
}}

Expand Down Expand Up @@ -227,8 +232,9 @@ from sia

{% if is_incremental() %}
where
date(cast(ano as int64), cast(mes as int64), 1)
> (select max(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }})
or date(cast(ano as int64), cast(mes as int64), 1)
< (select min(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }})
date(cast(ano as int64), cast(mes as int64), 1) not in (
select distinct (date(cast(ano as int64), cast(mes as int64), 1))
from {{ this }}
)

{% endif %}

0 comments on commit 6eb1e78

Please sign in to comment.