diff --git a/models/br_inep_censo_escolar/br_inep_censo_escolar__turma.sql b/models/br_inep_censo_escolar/br_inep_censo_escolar__turma.sql index 07e29452..26151518 100644 --- a/models/br_inep_censo_escolar/br_inep_censo_escolar__turma.sql +++ b/models/br_inep_censo_escolar/br_inep_censo_escolar__turma.sql @@ -10,6 +10,7 @@ cluster_by="sigla_uf", ) }} + select safe_cast(ano as int64) ano, safe_cast(sigla_uf as string) sigla_uf, diff --git a/models/br_inep_censo_escolar/code/main.py b/models/br_inep_censo_escolar/code/main.py index 4c248ffe..e8be1168 100644 --- a/models/br_inep_censo_escolar/code/main.py +++ b/models/br_inep_censo_escolar/code/main.py @@ -102,6 +102,14 @@ bq_storage_cols_order = [i["name"] for i in bq_cols["columns"]] +df["rede"].unique() # type: ignore + +df["rede"] = df["rede"].replace( # type: ignore + {"1": "federal", "2": "estadual", "3": "municipal", "4": "privada"} +) + +df["rede"].unique() # type: ignore + for keys, df_split in df.groupby(partitions): ano, sigla_uf = keys # type: ignore path = os.path.join(OUTPUT, f"ano={ano}", f"sigla_uf={sigla_uf}") diff --git a/models/br_inep_censo_escolar/schema.yml b/models/br_inep_censo_escolar/schema.yml index 3e599c66..e3e23636 100644 --- a/models/br_inep_censo_escolar/schema.yml +++ b/models/br_inep_censo_escolar/schema.yml @@ -1186,6 +1186,8 @@ models: - relationships: to: ref('br_bd_diretorios_brasil__escola') field: rede + - accepted_values: + values: [municipal, estadual, federal, privada] - name: id_escola description: Código da Escola - name: id_turma diff --git a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql index 65ef26b6..006eff6d 100644 --- a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql +++ b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql @@ -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:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (True)', + ], ) }} @@ -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 %}