-
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 #716 from basedosdados/staging/br_rf_cno
[dbt] br_rf_cno
- Loading branch information
Showing
8 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
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
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
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,23 @@ | ||
{{ | ||
config( | ||
alias="areas", | ||
schema="br_rf_cno", | ||
materialized="incremental", | ||
partition_by={ | ||
"field": "data_extracao", | ||
"data_type": "date", | ||
}, | ||
) | ||
}} | ||
|
||
select | ||
safe_cast(data as date) data_extracao, | ||
safe_cast(id_cno as string) id_cno, | ||
safe_cast(categoria as string) categoria, | ||
safe_cast(destinacao as string) destinacao, | ||
safe_cast(tipo_obra as string) tipo_obra, | ||
safe_cast(tipo_area as string) tipo_area, | ||
safe_cast(tipo_area_complementar as string) tipo_area_complementar, | ||
safe_cast(metragem as float64) metragem, | ||
from `basedosdados-staging.br_rf_cno_staging.areas` as t | ||
{% if is_incremental() %} where data > (select max(data) 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ | ||
config( | ||
alias="cnaes", | ||
schema="br_rf_cno", | ||
materialized="incremental", | ||
partition_by={ | ||
"field": "data_extracao", | ||
"data_type": "date", | ||
}, | ||
) | ||
}} | ||
select | ||
safe_cast(data as date) data_extracao, | ||
safe_cast(data_registro as date) data_registro, | ||
safe_cast(id_cno as string) id_cno, | ||
safe_cast(cnae_2_subclasse as string) cnae_2_subclasse, | ||
from `basedosdados-staging.br_rf_cno_staging.cnaes` as t | ||
{% if is_incremental() %} where data > (select max(data) 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ config(alias="dicionario", schema="br_rf_cno", materialized="table") }} | ||
select | ||
safe_cast(id_tabela as string) id_tabela, | ||
safe_cast(nome_coluna as string) nome_coluna, | ||
safe_cast(chave as string) chave, | ||
safe_cast(cobertura_temporal as string) cobertura_temporal, | ||
safe_cast(valor as string) valor, | ||
from `basedosdados-staging.br_rf_cno_staging.dicionario` 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{ | ||
config( | ||
alias="microdados", | ||
schema="br_rf_cno", | ||
materialized="incremental", | ||
partition_by={ | ||
"field": "data_extracao", | ||
"data_type": "date", | ||
}, | ||
pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", | ||
) | ||
}} | ||
|
||
select | ||
safe_cast(data as date) data_extracao, | ||
safe_cast(data_situacao as date) data_situacao, | ||
safe_cast(data_registro as date) data_registro, | ||
safe_cast(data_inicio as date) data_inicio, | ||
safe_cast(data_inicio_responsabilidade as date) data_inicio_responsabilidade, | ||
safe_cast(id_pais as string) id_pais, | ||
safe_cast(nome_pais as string) nome_pais, | ||
safe_cast(sigla_uf as string) sigla_uf, | ||
safe_cast(b.id_municipio as string) id_municipio, | ||
safe_cast(id_cno as string) id_cno, | ||
safe_cast(id_cno_vinculado as string) id_cno_vinculado, | ||
safe_cast(ltrim(situacao, '0') as string) situacao, | ||
safe_cast(id_responsavel as string) id_responsavel, | ||
safe_cast(nome_responsavel as string) nome_responsavel, | ||
safe_cast(ltrim(qualificacao_responsavel, '0') as string) qualificacao_responsavel, | ||
safe_cast(nome_empresarial as string) nome_empresarial, | ||
safe_cast(area as float64) area, | ||
safe_cast(unidade_medida as string) unidade_medida, | ||
safe_cast(bairro as string) bairro, | ||
safe_cast(cep as string) cep, | ||
safe_cast(logradouro as string) logradouro, | ||
safe_cast(tipo_logradouro as string) tipo_logradouro, | ||
safe_cast(numero_logradouro as string) numero_logradouro, | ||
safe_cast(complemento as string) complemento, | ||
safe_cast(caixa_postal as string) caixa_postal, | ||
from `basedosdados-staging.br_rf_cno_staging.microdados` microdados | ||
left join | ||
( | ||
select id_municipio, id_municipio_rf | ||
from `basedosdados.br_bd_diretorios_brasil.municipio` | ||
) b | ||
on ltrim(microdados.id_municipio_rf, '0') = b.id_municipio_rf | ||
|
||
{% if is_incremental() %} where data > (select max(data) 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{ | ||
config( | ||
alias="vinculos", | ||
schema="br_rf_cno", | ||
materialized="incremental", | ||
partition_by={ | ||
"field": "data_extracao", | ||
"data_type": "date", | ||
}, | ||
pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", | ||
) | ||
}} | ||
|
||
|
||
select | ||
safe_cast(data as date) data_extracao, | ||
safe_cast(data_registro as date) data_registro, | ||
safe_cast(data_inicio as date) data_inicio, | ||
safe_cast(data_fim as date) data_fim, | ||
safe_cast(id_cno as string) id_cno, | ||
safe_cast(id_responsavel as string) id_responsavel, | ||
safe_cast( | ||
ltrim(qualificacao_contribuinte, '0') as string | ||
) qualificacao_contribuinte, | ||
from `basedosdados-staging.br_rf_cno_staging.vinculos` as t | ||
|
||
{% if is_incremental() %} where data > (select max(data) from {{ this }}) {% endif %} |
Oops, something went wrong.