Skip to content

Commit

Permalink
Merge pull request #261 from basedosdados/br_rf_cafir
Browse files Browse the repository at this point in the history
[fix-dbt] `br_rf_cafir`
  • Loading branch information
folhesgabriel authored Sep 15, 2023
2 parents 39c3b1f + 6ce5065 commit 4ebcd84
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions models/br_rf_cafir/br_rf_cafir__imoveis_rurais.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"granularity": "day"
},
cluster_by=['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")
Expand Down Expand Up @@ -74,9 +75,8 @@ fixed_names as (
from lower_munis
LEFT JOIN (SELECT LOWER(REGEXP_REPLACE(NORMALIZE(nome, NFD), r"\pM", '')) nome_municipio, id_municipio, sigla_uf as sigla_uf1 FROM basedosdados.br_bd_diretorios_brasil.
municipio) as mun
ON lower_munis.nome_mun = mun.nome_municipio AND lower_munis.sigla_uf = mun.sigla_uf1)

SELECT
ON lower_munis.nome_mun = mun.nome_municipio AND lower_munis.sigla_uf = mun.sigla_uf1),
final as (SELECT
SAFE_CAST(data as DATE) data_referencia,
SAFE_CAST(FORMAT_DATE('%Y-%m-%d', safe.PARSE_DATE('%Y%m%d', data_inscricao))as DATE) AS data_inscricao,
SAFE_CAST(id_imovel_receita_federal as STRING) id_imovel_receita_federal,
Expand All @@ -93,7 +93,9 @@ SELECT
SAFE_CAST(sigla_uf as STRING) sigla_uf,
--- esta coluna não é identifica no dicionário nem nomeada nos arquivos
--- SAFE_CAST(LOWER(status_rever) as STRING) coluna_nao_identificada,
FROM fixed_names AS t
FROM fixed_names AS t)
select * from
final
{% if is_incremental() %}
WHERE data_referencia > (SELECT MAX(data_referencia) FROM {{ this }} )
{% endif %}

0 comments on commit 4ebcd84

Please sign in to comment.