Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbt] br_bcb_sicor #265

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ models:
+schema: br_bcb_agencia
br_bcb_estban:
+materialized: table
+schema: br_bcb_estban
+schema: br_bcb_estban
br_bcb_sicor:
+materialized: table
+schema: br_bcb_sicor
br_bcb_taxa_cambio:
+materialized: table
+schema: br_bcb_taxa_cambio
Expand Down
14 changes: 14 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__dicionario.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
alias = 'dicionario',
schema='br_bcb_sicor',
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_bcb_sicor_staging.dicionario AS t
24 changes: 24 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__empreendimento.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{
config(
alias = 'empreendimento',
schema='br_bcb_sicor',
materialized='table',
)
}}
SELECT
SAFE_CAST(id_empreendimento AS STRING) id_empreendimento,
SAFE_CAST(data_inicio_empreendimento AS DATE) data_inicio,
SAFE_CAST(data_fim_empreendimento AS DATE) data_fim,
SAFE_CAST(finalidade AS STRING) finalidade,
SAFE_CAST(atividade AS STRING) atividade,
SAFE_CAST(modalidade AS STRING) modalidade,
SAFE_CAST(produto AS STRING) produto,
SAFE_CAST(variedade AS STRING) variedade,
SAFE_CAST(cesta_safra AS STRING) cesta_safra,
SAFE_CAST(zoneamento AS STRING) zoneamento,
SAFE_CAST(unidade_medida AS STRING) unidade_medida,
SAFE_CAST(unidade_medida_previsao_producao AS STRING) unidade_medida_previsao_producao,
SAFE_CAST(consorcio AS STRING) consorcio,
SAFE_CAST(cedula_mae AS STRING) cedula_mae,
SAFE_CAST(id_tipo_cultura AS STRING) id_tipo_cultura
FROM basedosdados-staging.br_bcb_sicor_staging.empreendimento AS t
26 changes: 26 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__microdados_liberacao.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{
config(
alias = 'microdados_liberacao',
schema='br_bcb_sicor',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2013,
"end": 2024,
"interval": 1}
},
cluster_by = ["mes"]
)
}}


SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(mes AS INT64) mes,
SAFE_CAST(data_liberacao AS DATE) data_liberacao,
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(valor_liberado AS FLOAT64) valor_liberado
FROM basedosdados-staging.br_bcb_sicor_staging.microdados_liberacao AS t
68 changes: 68 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__microdados_operacao.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{
config(
alias = 'microdados_operacao',
schema='br_bcb_sicor',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2013,
"end": 2024,
"interval": 1}
},
cluster_by = ["sigla_uf", "plano_safra_emissao"]
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(mes AS INT64) mes,
SAFE_CAST(data_emissao AS DATE) data_emissao,
SAFE_CAST(ano_vencimento AS INT64) ano_vencimento,
SAFE_CAST(mes_vencimento AS INT64) mes_vencimento,
SAFE_CAST(data_vencimento AS DATE) data_vencimento,
SAFE_CAST(plano_safra_emissao AS STRING) plano_safra_emissao,
SAFE_CAST(plano_safra_vencimento AS STRING) plano_safra_vencimento,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(id_categoria_emitente AS STRING) id_categoria_emitente,
SAFE_CAST(id_empreendimento AS STRING) id_empreendimento,
SAFE_CAST(id_fase_ciclo_producao AS STRING) id_fase_ciclo_producao,
SAFE_CAST(id_fonte_recurso AS STRING) id_fonte_recurso,
SAFE_CAST(id_instrumento_credito AS STRING) id_instrumento_credito,
SAFE_CAST(id_programa AS STRING) id_programa,
SAFE_CAST(id_referencia_bacen_investimento AS STRING) id_referencia_bacen_investimento,
SAFE_CAST(id_subprograma AS STRING) id_subprograma,
SAFE_CAST(id_tipo_agricultura AS STRING) id_tipo_agricultura,
SAFE_CAST(id_tipo_cultivo AS STRING) id_tipo_cultivo,
SAFE_CAST(id_tipo_encargo_financeiro AS STRING) id_tipo_encargo_financeiro,
SAFE_CAST(id_tipo_grao_semente AS STRING) id_tipo_grao_semente,
SAFE_CAST(id_tipo_integracao_consorcio AS STRING) id_tipo_integracao_consorcio,
SAFE_CAST(id_tipo_irrigacao AS STRING) id_tipo_irrigacao,
SAFE_CAST(id_tipo_seguro AS STRING) id_tipo_seguro,
SAFE_CAST(cnpj_agente_investimento AS STRING) cnpj_agente_investimento,
SAFE_CAST(cnpj_basico_instituicao_financeira AS STRING) cnpj_basico_instituicao_financeira,
SAFE_CAST(id_contrato_sistema_tesouro_nacional AS STRING) id_contrato_sistema_tesouro_nacional,
SAFE_CAST(cnpj_cadastrante AS STRING) cnpj_cadastrante,
SAFE_CAST(data_fim_colheita AS DATE) data_fim_colheita,
SAFE_CAST(data_fim_plantio AS DATE) data_fim_plantio,
SAFE_CAST(data_inicio_colheita AS DATE) data_inicio_colheita,
SAFE_CAST(data_inicio_plantio AS DATE) data_inicio_plantio,
SAFE_CAST(area_financiada AS FLOAT64) area_financiada,
SAFE_CAST(valor_aliquota_proagro AS FLOAT64) valor_aliquota_proagro,
SAFE_CAST(valor_parcela_credito AS FLOAT64) valor_parcela_credito,
SAFE_CAST(valor_prestacao_investimento AS FLOAT64) valor_prestacao_investimento,
SAFE_CAST(valor_recurso_proprio AS FLOAT64) valor_recurso_proprio,
SAFE_CAST(valor_receita_bruta_esperada AS FLOAT64) valor_receita_bruta_esperada,
SAFE_CAST(valor_recurso_proprio_srv AS FLOAT64) valor_recurso_proprio_srv,
SAFE_CAST(valor_quantidade_itens_financiados AS FLOAT64) valor_quantidade_itens_financiados,
SAFE_CAST(valor_produtividade_obtida AS FLOAT64) valor_produtividade_obtida,
SAFE_CAST(valor_previsao_producao AS FLOAT64) valor_previsao_producao,
SAFE_CAST(taxa_juro AS FLOAT64) taxa_juro,
SAFE_CAST(taxa_juro_encargo_financeiro_posfixado AS FLOAT64) taxa_juro_encargo_financeiro_posfixado,
SAFE_CAST(valor_percentual_custo_efetivo_total AS FLOAT64) valor_percentual_custo_efetivo_total,
SAFE_CAST(valor_percentual_risco_fundo_constitucional AS FLOAT64) valor_percentual_risco_fundo_constitucional,
SAFE_CAST(valor_percentual_risco_stn AS FLOAT64) valor_percentual_risco_stn
FROM basedosdados-staging.br_bcb_sicor_staging.microdados_operacao AS t
27 changes: 27 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__microdados_saldo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{
config(
alias = 'microdados_saldo',
schema='br_bcb_sicor',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2013,
"end": 2024,
"interval": 1}
},
cluster_by = ["mes"]
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(mes AS INT64) mes,
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(id_situacao_operacao AS STRING) id_situacao_operacao,
SAFE_CAST(valor_medio_diario AS FLOAT64) valor_medio_diario,
SAFE_CAST(valor_medio_diario_vincendo AS FLOAT64) valor_medio_diario_vincendo,
SAFE_CAST(valor_ultimo_dia AS FLOAT64) valor_ultimo_dia
FROM basedosdados-staging.br_bcb_sicor_staging.microdados_saldo AS t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
alias = 'recurso_publico_complemento_operacao',
schema='br_bcb_sicor',
materialized='table',
partition_by = {
"field": "id_municipio",
"data_type": "string"
}
)
}}

SELECT
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(id_referencia_bacen_efetivo AS STRING) id_referencia_bacen_efetivo,
SAFE_CAST(id_agencia AS STRING) id_agencia
FROM basedosdados-staging.br_bcb_sicor_staging.recurso_publico_complemento_operacao AS t
15 changes: 15 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__recurso_publico_cooperado.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{
config(
alias = 'recurso_publico_cooperado',
schema='br_bcb_sicor',
materialized='table',
)
}}

SELECT
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(tipo_cpf_cnpj AS STRING) tipo_cpf_cnpj,
SAFE_CAST(tipo_pessoa AS STRING) tipo_pessoa,
SAFE_CAST(valor_parcela AS FLOAT64) valor_parcela
FROM basedosdados-staging.br_bcb_sicor_staging.recurso_publico_cooperado AS t
16 changes: 16 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__recurso_publico_gleba.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
alias = 'recurso_publico_gleba',
schema='br_bcb_sicor',
materialized='table'
)
}}
SELECT
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(numero_identificador_gleba AS STRING) numero_identificador_gleba,
SAFE_CAST(indice_indice_gleba AS INT64) indice_gleba,
SAFE_CAST(indice_indice_ponto AS INT64) indice_ponto,
ST_GEOGPOINT(SAFE_CAST(longitude AS FLOAT64),SAFE_CAST(latitude AS FLOAT64)) ponto,
SAFE_CAST(altitude AS FLOAT64) altitude
FROM basedosdados-staging.br_bcb_sicor_staging.recurso_publico_gleba AS t
16 changes: 16 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__recurso_publico_mutuario.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
alias = 'recurso_publico_mutuario',
schema='br_bcb_sicor',
materialized='table',
)
}}


SELECT
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(indicador_sexo AS INT64) indicador_sexo,
SAFE_CAST(tipo_cpf_cnpj AS STRING) tipo_cpf_cnpj,
SAFE_CAST(tipo_beneficiario AS STRING) tipo_beneficiario,
SAFE_CAST(id_dap AS STRING) id_dap
FROM basedosdados-staging.br_bcb_sicor_staging.recurso_publico_mutuario AS t
16 changes: 16 additions & 0 deletions models/br_bcb_sicor/br_bcb_sicor__recurso_publico_propriedade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
alias = 'recurso_publico_propriedade',
schema='br_bcb_sicor',
materialized='table',
)
}}

SELECT
SAFE_CAST(id_referencia_bacen AS STRING) id_referencia_bacen,
SAFE_CAST(numero_ordem AS STRING) numero_ordem,
SAFE_CAST(tipo_cpf_cnpj AS STRING) tipo_cpf_cnpj,
SAFE_CAST(id_sncr AS STRING) id_sncr,
SAFE_CAST(id_nirf AS STRING) id_nirf,
SAFE_CAST(id_car AS STRING) id_car
FROM basedosdados-staging.br_bcb_sicor_staging.recurso_publico_propriedade AS t
Loading
Loading