-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into br_inep_censo_escolar__escola
- Loading branch information
Showing
15 changed files
with
361 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -137,6 +137,7 @@ select | |
safe_cast(dialise as int64) indicador_existencia_requisito_dialise, | ||
safe_cast(quimradi as int64) indicador_existencia_requisito_quimio_radio | ||
from cnes_add_muni as t | ||
|
||
{% if is_incremental() %} | ||
where | ||
date(cast(ano as int64), cast(mes as int64), 1) | ||
|
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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -24,16 +24,20 @@ with | |
from `basedosdados-staging.br_ms_cnes_staging.equipamento` | ||
where cnes is not null | ||
), | ||
unique_raw_cnes_equipamento as ( | ||
-- 2. distinct nas linhas | ||
select distinct * from raw_cnes_equipamento | ||
), | ||
cnes_add_muni as ( | ||
-- 2. Adicionar id_municipio de 7 dígitos | ||
-- 3. Adicionar id_municipio de 7 dígitos | ||
select * | ||
from raw_cnes_equipamento | ||
from unique_raw_cnes_equipamento | ||
left join | ||
( | ||
select id_municipio, id_municipio_6, | ||
from `basedosdados.br_bd_diretorios_brasil.municipio` | ||
) as mun | ||
on raw_cnes_equipamento.codufmun = mun.id_municipio_6 | ||
on unique_raw_cnes_equipamento.codufmun = mun.id_municipio_6 | ||
) | ||
select | ||
safe_cast(ano as int64) as ano, | ||
|
@@ -48,6 +52,7 @@ select | |
safe_cast(ind_sus as int64) as indicador_equipamento_disponivel_sus, | ||
safe_cast(ind_nsus as int64) as indicador_equipamento_indisponivel_sus | ||
from cnes_add_muni | ||
|
||
{% if is_incremental() %} | ||
where | ||
date(cast(ano as int64), cast(mes as int64), 1) | ||
|
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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -59,14 +59,15 @@ select | |
safe_cast(tp_desat as string) as tipo_desativacao_equipe, | ||
safe_cast(substr(dt_desat, 1, 4) as int64) as ano_desativacao_equipe, | ||
safe_cast(substr(dt_desat, 5, 6) as int64) as mes_desativacao_equipe, | ||
safe_cast(quilombo as string) as indicador_atende_populacao_assistida_quilombolas, | ||
safe_cast(assentad as string) as indicador_atende_populacao_assistida_assentados, | ||
safe_cast(popgeral as string) as indicador_atende_populacao_assistida_geral, | ||
safe_cast(escola as string) as indicador_atende_populacao_assistida_escolares, | ||
safe_cast(indigena as string) as indicador_atende_populacao_assistida_indigena, | ||
safe_cast(pronasci as string) as indicador_atende_populacao_assistida_pronasci, | ||
safe_cast(quilombo as int64) as indicador_atende_populacao_assistida_quilombolas, | ||
safe_cast(assentad as int64) as indicador_atende_populacao_assistida_assentados, | ||
safe_cast(popgeral as int64) as indicador_atende_populacao_assistida_geral, | ||
safe_cast(escola as int64) as indicador_atende_populacao_assistida_escolares, | ||
safe_cast(indigena as int64) as indicador_atende_populacao_assistida_indigena, | ||
safe_cast(pronasci as int64) as indicador_atende_populacao_assistida_pronasci, | ||
from cnes_add_muni | ||
{% 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 }}) | ||
|
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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -239,7 +239,7 @@ select | |
safe_cast(ap03cv04 as int64) indicador_atendimento_sadt_plano_seguro_terceiro, | ||
safe_cast(ap03cv05 as int64) indicador_atendimento_sadt_plano_saude_publico, | ||
safe_cast(ap03cv06 as int64) indicador_atendimento_sadt_plano_saude_privado, | ||
safe_cast(ap04cv01 as string) indicador_atendimento_urgencia_sus, | ||
safe_cast(ap04cv01 as int64) indicador_atendimento_urgencia_sus, | ||
safe_cast(ap04cv02 as int64) indicador_atendimento_urgencia_privado, | ||
safe_cast(ap04cv03 as int64) indicador_atendimento_urgencia_plano_seguro_proprio, | ||
safe_cast(ap04cv04 as int64) indicador_atendimento_urgencia_plano_seguro_terceiro, | ||
|
@@ -263,9 +263,9 @@ select | |
safe_cast(ap07cv04 as int64) indicador_atendimento_regulacao_plano_seguro_terceiro, | ||
safe_cast(ap07cv05 as int64) indicador_atendimento_regulacao_plano_saude_publico, | ||
safe_cast(ap07cv06 as int64) indicador_atendimento_regulacao_plano_saude_privado | ||
from cnes_add_muni as t | ||
{% 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 }}) | ||
{% 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 |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
partition_by={ | ||
"field": "ano", | ||
"data_type": "int64", | ||
"range": {"start": 2005, "end": 2023, "interval": 1}, | ||
"range": {"start": 2005, "end": 2024, "interval": 1}, | ||
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -64,6 +64,7 @@ select | |
from cnes_add_muni as t | ||
{% 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 }}) | ||
{% 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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -62,9 +62,9 @@ select | |
) data_portaria, | ||
cast(substr(maportar, 1, 4) as int64) as ano_portaria, | ||
cast(substr(maportar, 5, 2) as int64) as mes_portaria, | ||
from cnes_add_muni as t | ||
{% 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 }}) | ||
{% 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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -69,6 +69,7 @@ select | |
from cnes_add_muni as t | ||
{% 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 }}) | ||
{% 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 |
---|---|---|
|
@@ -10,16 +10,16 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
with | ||
raw_cnes_habilitacaol as ( | ||
-- 1. Retirar linhas com id_estabelecimento_cnes nulo | ||
select * | ||
from `basedosdados-staging.br_ms_cnes_staging.habilitacao` | ||
from `basedosdados-dev.br_ms_cnes_staging.habilitacao` | ||
where cnes is not null | ||
), | ||
raw_cnes_habilitacao_without_duplicates as ( | ||
|
@@ -33,7 +33,7 @@ with | |
left join | ||
( | ||
select id_municipio, id_municipio_6, | ||
from `basedosdados.br_bd_diretorios_brasil.municipio` | ||
from `basedosdados-dev.br_bd_diretorios_brasil.municipio` | ||
) as mun | ||
on raw_cnes_habilitacao_without_duplicates.codufmun = mun.id_municipio_6 | ||
) | ||
|
@@ -45,10 +45,10 @@ select | |
safe_cast(id_municipio as string) id_municipio, | ||
safe_cast(cnes as string) id_estabelecimento_cnes, | ||
safe_cast(nuleitos as int64) quantidade_leitos, | ||
cast(substr(cmpt_ini, 1, 4) as int64) as ano_competencia_inicial, | ||
cast(substr(cmpt_ini, 5, 2) as int64) as mes_competencia_inicial, | ||
cast(substr(cmpt_fim, 1, 4) as int64) as ano_competencia_final, | ||
cast(substr(cmpt_fim, 5, 2) as int64) as mes_competencia_final, | ||
safe_cast(substr(cmpt_ini, 1, 4) as int64) as ano_competencia_inicial, | ||
safe_cast(substr(cmpt_ini, 5, 2) as int64) as mes_competencia_inicial, | ||
safe_cast(substr(cmpt_fim, 1, 4) as int64) as ano_competencia_final, | ||
safe_cast(substr(cmpt_fim, 5, 2) as int64) as mes_competencia_final, | ||
safe_cast(sgruphab as string) tipo_habilitacao, | ||
case | ||
when | ||
|
@@ -78,8 +78,9 @@ select | |
substring(dtportar, 1, 2) | ||
) as date | ||
) data_portaria, | ||
cast(substr(maportar, 1, 4) as int64) as ano_portaria, | ||
cast(substr(maportar, 5, 2) as int64) as mes_portaria, | ||
|
||
safe_cast(substr(maportar, 1, 4) as int64) as ano_portaria, | ||
safe_cast(substr(maportar, 5, 2) as int64) as mes_portaria, | ||
from cnes_add_muni as t | ||
{% if is_incremental() %} | ||
where | ||
|
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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
}, | ||
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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', | ||
'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)', | ||
], | ||
) | ||
}} | ||
|
@@ -67,6 +67,7 @@ select | |
from cnes_add_muni as t | ||
{% 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 }}) | ||
{% endif %} |
Oops, something went wrong.