-
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 pull request #522 from basedosdados/feat/censo-setor-censitario
[dbt]: add `domicilio_morador_setor_censitario` & `br_bd_diretorios_brasil.setor_censitario`
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
models/br_bd_diretorios_brasil/br_bd_diretorios_brasil__setor_censitario.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,60 @@ | ||
{{ | ||
config( | ||
alias="setor_censitario", | ||
schema="br_bd_diretorios_brasil", | ||
materialized="table", | ||
) | ||
}} | ||
with | ||
censo_2022 as ( | ||
select | ||
2022 as ano, | ||
cd_setor as id_setor_censitario, | ||
cd_mun as id_municipio, | ||
cast(null as string) as id_rm, | ||
cast(null as string) nome_rm, | ||
cd_dist as id_distrito, | ||
nm_dist as nome_distrito, | ||
cd_subdist as id_subdistrito, | ||
nm_subdist as nome_subdistrito, | ||
cast(null as string) id_bairro, | ||
cast(null as string) nome_bairro, | ||
cast(null as string) sigla_uf, | ||
cast(null as string) situacao_setor, | ||
cast(null as string) tipo_setor, | ||
cd_micro as id_microrregiao, | ||
nm_micro as nome_microrregiao, | ||
cd_meso as id_mesorregiao, | ||
nm_meso as nome_mesorregiao, | ||
cd_rgi as id_regiao_imediata, | ||
nm_rgi as nome_regiao_imediata, | ||
cd_rgint as id_regiao_intermediaria, | ||
nm_rgint as nome_regiao_intermediaria, | ||
cd_concurb as id_concentracao_urbana, | ||
nm_concurb as nome_concentracao_urbana, | ||
from | ||
`basedosdados-staging.br_ibge_censo_2022_staging.domicilio_morador_setor_censitario` | ||
|
||
), | ||
|
||
censo_2010 as ( | ||
select | ||
*, | ||
cast(null as string) id_microrregiao, | ||
cast(null as string) nome_microrregiao, | ||
cast(null as string) id_mesorregiao, | ||
cast(null as string) nome_mesorregiao, | ||
cast(null as string) id_regiao_imediata, | ||
cast(null as string) nome_regiao_imediata, | ||
cast(null as string) id_regiao_intermediaria, | ||
cast(null as string) nome_regiao_intermediaria, | ||
cast(null as string) id_concentracao_urbana, | ||
cast(null as string) nome_concentracao_urbana | ||
from `basedosdados-staging.br_bd_diretorios_brasil.setor_censitario` | ||
) | ||
|
||
select * | ||
from censo_2022 | ||
union all | ||
select * | ||
from censo_2010 |
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
25 changes: 25 additions & 0 deletions
25
models/br_ibge_censo_2022/br_ibge_censo_2022__domicilio_morador_setor_censitario.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,25 @@ | ||
{{ | ||
config( | ||
alias="domicilio_morador_setor_censitario", | ||
schema="br_ibge_censo_2022", | ||
cluster_by=["id_uf", "id_municipio"], | ||
) | ||
}} | ||
select | ||
safe_cast(cd_uf as string) id_uf, | ||
safe_cast(cd_mun as string) id_municipio, | ||
safe_cast(cd_setor as string) id_setor_censitario, | ||
safe_cast(area_km2 as float64) area_setor, | ||
safe_cast( | ||
st_geogfromwkb(geometry, planar => true, make_valid => true) as geography | ||
) geometria, | ||
safe_cast(v0001 as int64) pessoas, | ||
safe_cast(v0002 as int64) domicilios, | ||
safe_cast(v0003 as int64) domicilios_particulares, | ||
safe_cast(v0004 as int64) domicilios_coletivos, | ||
safe_cast(v0005 as float64) media_moradores_domicilios, | ||
safe_cast(v0006 as float64) porcentagem_domicilios_imputados, | ||
safe_cast(v0007 as int64) domicilios_particulares_ocupados, | ||
from | ||
`basedosdados-staging.br_ibge_censo_2022_staging.domicilio_morador_setor_censitario` | ||
as t |
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