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_camara_dados_abertos #476

Merged
merged 7 commits into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ models:
+schema: mundo_transfermarkt_competicoes_internacionais
world_ampas_oscar:
+materialized: table
+schema: world_ampas_oscar
+schema: world_ampas_oscar
world_iea_pirls:
+materialized: table
+schema: world_iea_pirls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,68 @@
with
sql as (
select
regexp_extract(uri, r'/([^/]+)$') as id_deputado,
safe_cast(nome as string) nome,
safe_cast(nome_civil as string) nome_civil,
safe_cast(data_nascimento as date) data_nascimento,
safe_cast(data_falecimento as date) data_falecimento,
regexp_extract(id_deputado, r'/([^/]+)$') as id_deputado,
safe_cast(nomecivil as string) nome_civil,
safe_cast(datanascimento as date) data_nascimento,
safe_cast(datafalecimento as date) data_falecimento,
case
when id_municipio_nascimento = 'SAO PAULO'
when municipionascimento = 'SAO PAULO'
then 'São Paulo'
when id_municipio_nascimento = 'Moji-Mirim'
when municipionascimento = 'Moji-Mirim'
then 'Mogi Mirim'
when id_municipio_nascimento = "São Lourenço D'Oeste"
when municipionascimento = "São Lourenço D'Oeste"
then 'São Lourenço do Oeste'
when id_municipio_nascimento = "Santa Bárbara D'Oeste"
when municipionascimento = "Santa Bárbara D'Oeste"
then "Santa Bárbara d'Oeste"
when id_municipio_nascimento = "Araióses"
when municipionascimento = "Araióses"
then "Araioses"
when id_municipio_nascimento = "Cacador"
when municipionascimento = "Cacador"
then "Caçador"
when id_municipio_nascimento = "Pindaré Mirim"
when municipionascimento = "Pindaré Mirim"
then "Pindaré-Mirim"
when id_municipio_nascimento = "Belém de São Francisco"
when municipionascimento = "Belém de São Francisco"
then "Belém do São Francisco"
when id_municipio_nascimento = "Sud Menucci"
when municipionascimento = "Sud Menucci"
then "Sud Mennucci"
when id_municipio_nascimento = 'Duerê'
when municipionascimento = 'Duerê'
then "Dueré"
when id_municipio_nascimento = 'Santana do Livramento'
when municipionascimento = 'Santana do Livramento'
then "Sant'Ana do Livramento"
when id_municipio_nascimento = "Herval D'Oeste"
when municipionascimento = "Herval D'Oeste"
then "Herval d'Oeste"
when id_municipio_nascimento = "Guaçui"
when municipionascimento = "Guaçui"
then "Guaçuí"
when id_municipio_nascimento = "Lençois Paulista"
when municipionascimento = "Lençois Paulista"
then "Lençóis Paulista"
when id_municipio_nascimento = "Amambaí"
when municipionascimento = "Amambaí"
then "Amambai"
when id_municipio_nascimento = "Santo Estevão"
when municipionascimento = "Santo Estevão"
then "Santo Estêvão"
when id_municipio_nascimento = "Poxoréu"
when municipionascimento = "Poxoréu"
then "Poxoréo"
when id_municipio_nascimento = "Trajano de Morais"
when municipionascimento = "Trajano de Morais"
then "Trajano de Moraes"
else id_municipio_nascimento
end as id_municipio_nascimento,
safe_cast(sigla_uf_nascimento as string) sigla_uf_nascimento,
case
when sexo = 'M'
then 'Masculino'
when sexo = 'F'
then 'Feminino'
else sexo
end as sexo,
safe_cast(id_inicial_legislatura as string) id_inicial_legislatura,
safe_cast(id_final_legislatura as string) id_final_legislatura,
safe_cast(url_site as string) url_site,
safe_cast(url_rede_social as string) url_rede_social,
else municipionascimento
end as municipionascimento,
safe_cast(ufnascimento as string) sigla_uf_nascimento,
replace(
replace(safe_cast(siglasexo as string), 'M', 'Masculino'),
'F',
'Feminino'
) sexo,
safe_cast(idlegislaturainicial as string) id_inicial_legislatura,
safe_cast(idlegislaturafinal as string) id_final_legislatura,
safe_cast(urlwebsite as string) url_site,
safe_cast(urlwebsite as string) url_rede_social,
from `basedosdados-staging.br_camara_dados_abertos_staging.deputado`
),
uniao_valores as (
select a.*, b.nome as name_id_municipio, b.id_municipio, b.sigla_uf
from sql as a
left join
`basedosdados.br_bd_diretorios_brasil.municipio` as b
on a.id_municipio_nascimento = b.nome
on a.municipionascimento = b.nome
and a.sigla_uf_nascimento = b.sigla_uf
)
select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ config(alias="deputado_ocupacao", schema="br_camara_dados_abertos") }}
select
safe_cast(ano_inicio as int64) ano_inicio,
safe_cast(ano_fim as int64) ano_fim,
safe_cast(id_deputado as string) id_deputado,
safe_cast(sigla_uf as string) sigla_uf,
select distinct
safe_cast(id as string) id_deputado,
safe_cast(anoinicio as int64) ano_inicio,
safe_cast(anofim as int64) ano_fim,
safe_cast(entidadeuf as string) sigla_uf,
safe_cast(entidade as string) entidade,
safe_cast(titulo as string) titulo,
from `basedosdados-staging.br_camara_dados_abertos_staging.deputado_ocupacao` as t
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{{ config(alias="deputado_profissao", schema="br_camara_dados_abertos") }}
select
safe_cast(id_deputado as int64) id_deputado,
select distinct
safe_cast(id as string) id_deputado,
safe_cast(
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(data)), 'T')[
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(datahora)), 'T')[
offset(0)
] as date
) data,
safe_cast(
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(data)), 'T')[
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(datahora)), 'T')[
offset(1)
] as time
) horario,
safe_cast(id_profissao as string) id_profissao,
safe_cast(codtipoprofissao as string) id_profissao,
safe_cast(titulo as string) titulo,
from `basedosdados-staging.br_camara_dados_abertos_staging.deputado_profissao` as t
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{ config(alias="despesa", schema="br_camara_dados_abertos") }}
select distinct
safe_cast(initcap(txnomeparlamentar) as string) nome_parlamentar,
safe_cast(replace(cpf, ".0", "") as string) cpf,
safe_cast(replace(idecadastro, ".0", "") as string) id_deputado,
safe_cast(nulegislatura as int64) ano_legislatura,
safe_cast(sguf as string) sigla_uf,
safe_cast(sgpartido as string) sigla_partido,
safe_cast(codlegislatura as string) id_legislatura,
safe_cast(txtdescricao as string) categoria_despesa,
safe_cast(txtdescricaoespecificacao as string) subcategoria_despesa,
safe_cast(txtfornecedor as string) fornecedor,
safe_cast(txtcnpjcpf as string) cnpj_cpf_fornecedor,
safe_cast(txtnumero as string) numero_documento_fiscal,
case
when indtipodocumento = '0'
then 'Nota fiscal'
when indtipodocumento = '1'
then 'Recibo ou outros'
when indtipodocumento = '2'
then 'Documento emitido no exterior'
when indtipodocumento = '3'
then 'Despesa do Parlasul'
when indtipodocumento = '4'
then 'Nota fiscal eletrônica'
when indtipodocumento = '5'
then 'Nota fiscal eletrônica'
else indtipodocumento
end as tipo_documento,
safe_cast(numano as int64) as ano_competencia,
safe_cast(nummes as int64) as mes_competencia,
safe_cast(
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(datemissao)), 'T')[
offset(0)
] as date
) data_emissao,
safe_cast(vlrdocumento as float64) valor_documento,
safe_cast(vlrglosa as float64) valor_retido,
safe_cast(vlrliquido as float64) valor_liquido,
safe_cast(numparcela as int64) numero_parcela,
safe_cast(txtpassageiro as string) nome_passageiro,
safe_cast(txttrecho as string) descricao_passagem_aerea,
safe_cast(datpagamentorestituicao as datetime) data_pagamento_restituicao,
safe_cast(vlrrestituicao as float64) valor_restituicao,
safe_cast(urldocumento as string) url_documento,
from `basedosdados-staging.br_camara_dados_abertos_staging.despesa` as t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# register flow
{{ config(alias="evento", schema="br_camara_dados_abertos") }}
select
safe_cast(id as string) id,
safe_cast(id as string) id_evento,
safe_cast(urldocumentopauta as string) url_documento_pauta,
safe_cast(
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(datahorainicio)), 'T')[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# register flow
{{ config(alias="evento_orgao", schema="br_camara_dados_abertos") }}
select
safe_cast(idevento as string) id_evento,
safe_cast(idorgao as string) id_orgao,
safe_cast(siglaorgao as string) sigla_orgao,
safe_cast(siglaorgao as string) sigla_orgao
from `basedosdados-staging.br_camara_dados_abertos_staging.evento_orgao` as t
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# register flow
{{ config(alias="evento_presenca_deputado", schema="br_camara_dados_abertos") }}
select distinct
safe_cast(idevento as string) id_evento,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# register flow
{{ config(alias="evento_requerimento", schema="br_camara_dados_abertos") }}
select
safe_cast(idevento as string) id_evento,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# register flow
{{ config(alias="frente", schema="br_camara_dados_abertos") }}
select
safe_cast(id as string) id,
safe_cast(id as string) id_frente,
safe_cast(titulo as string) titulo,
safe_cast(datacriacao as date) data_criacao,
safe_cast(idlegislatura as string) id_legislatura,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# register flow
{{ config(alias="frente_deputado", schema="br_camara_dados_abertos") }}
select
select distinct
safe_cast(id as string) id_frente,
safe_cast(titulo as string) titulo,
safe_cast(id_deputado as string) id_deputado,
safe_cast(titulo as string) titulo_deputado,
safe_cast(replace(id_deputado, ".0", "") as string) id_deputado,
initcap(nome_deputado) nome_deputado,
safe_cast(titulo_deputado as string) titulo_deputado,
safe_cast(url_foto_deputado as string) url_foto_deputado,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# register flow
{{ config(alias="funcionario", schema="br_camara_dados_abertos") }}
select distinct
safe_cast(nome as string) nome,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(alias="legislatura", schema="br_camara_dados_abertos") }}
select
safe_cast(anoeleicao as int64) ano,
safe_cast(idlegislatura as string) id,
safe_cast(idlegislatura as string) id_legislatura,
safe_cast(uri as string) url,
safe_cast(datainicio as date) data_inicio,
safe_cast(datafim as date) data_final,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config(alias="legislatura_mesa", schema="br_camara_dados_abertos") }}
select
safe_cast(idlegislatura as string) id,
safe_cast(idlegislatura as string) id_legislatura,
safe_cast(datainicio as datetime) data_inicio,
safe_cast(datafim as datetime) data_final,
safe_cast(idorgao as string) id_orgao,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{ config(alias="licitacao", schema="br_camara_dados_abertos") }}
select
safe_cast(ano as int64) ano_licitacao,
safe_cast(idlicitacao as string) id_licitacao,
safe_cast(anoprocesso as int64) ano_processo,
safe_cast(numprocesso as string) id_processo,
safe_cast(objeto as string) objeto,
safe_cast(modalidade as string) modalidade,
safe_cast(tipo as string) tipo,
safe_cast(situacao as string) situacao,
safe_cast(dataabertura as date) data_abertura,
safe_cast(datapublicacao as date) data_publicacao,
safe_cast(dataautorizacao as date) data_autorizacao,
safe_cast(numitens as int64) quantidade_item,
safe_cast(numunidades as int64) quantidade_unidade,
safe_cast(numpropostas as int64) quantidade_proposta,
safe_cast(numcontratos as int64) quantidade_contrato,
safe_cast(vlrestimado as int64) valor_estimado,
safe_cast(vlrcontratado as int64) valor_contratado,
safe_cast(vlrpago as int64) valor_pago,
from `basedosdados-staging.br_camara_dados_abertos_staging.licitacao` as t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{ config(alias="licitacao_contrato", schema="br_camara_dados_abertos") }}
select distinct
safe_cast(ano as int64) ano_licitacao,
safe_cast(idlicitacao as string) id_licitacao,
safe_cast(anocontrato as int64) ano_contrato,
safe_cast(numcontrato as string) id_contrato,
safe_cast(tipocontrato as string) tipo_contrato,
safe_cast(situacaocontrato as string) situacao_contrato,
safe_cast(objeto as string) descricao,
safe_cast(dataassinatura as date) data_assinatura,
safe_cast(datapublicacao as date) data_publicacao,
safe_cast(datainiciovigenciaoriginal as date) data_inicio_contrato,
safe_cast(datafimvigenciaoriginal as date) data_fim_contrato,
safe_cast(datafimultimavigencia as date) data_fim_ultima_vigencia,
safe_cast(fornecedornome as string) nome_fornecedor,
safe_cast(fornecedorendereco as string) endereco_fornecedor,
safe_cast(fornecedorcidade as string) cidade_fornecedor,
safe_cast(fornecedorsiglauf as string) sigla_uf_fornecedor,
safe_cast(fornecedorcpfcnpj as string) cpf_cnpj_fornecedor,
safe_cast(vlroriginal as int64) valor_original,
safe_cast(vlrtotal as int64) valor_total,
from `basedosdados-staging.br_camara_dados_abertos_staging.licitacao_contrato` as t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{ config(alias="licitacao_item", schema="br_camara_dados_abertos") }}
select
safe_cast(ano as int64) ano_licitacao,
safe_cast(idlicitacao as string) id_licitacao,
safe_cast(numitem as string) id_item,
safe_cast(replace(numsubitem, '.0', '') as string) id_sub_item,
safe_cast(descricao as string) descricao,
safe_cast(especificacao as string) especificacao,
safe_cast(unidade as string) unidade,
safe_cast(qtdlicitada as int64) quantidade_licitada,
safe_cast(replace(vlrunitarioestimado, ".0", "") as int64) valor_unitario_estimado,
safe_cast(replace(qtdcontratada, ".0", "") as int64) quantidade_contratada,
safe_cast(
replace(vlrunitariocontratado, ".0", "") as int64
) valor_unitario_contratado,
safe_cast(replace(vlrtotalcontratado, ".0", "") as int64) valor_total_contratado,
safe_cast(fornecedorcpfcnpj as string) cpf_cnpj_fornecedor,
safe_cast(fornecedornome as string) nome_fornecedor,
safe_cast(numcontrato as string) id_contrato,
safe_cast(replace(anocontrato, ".0", "") as int64) ano_contrato,
safe_cast(tipocontrato as string) tipo_contrato,
safe_cast(situacaoitem as string) situacao_item,
safe_cast(observacoes as string) observacao,
safe_cast(naturezadespesa as string) natureza_despesa,
safe_cast(programatrabalho as string) programa_trabalho,
from `basedosdados-staging.br_camara_dados_abertos_staging.licitacao_item` as t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{ config(alias="licitacao_pedido", schema="br_camara_dados_abertos") }}
select
safe_cast(ano as int64) ano_licitacao,
safe_cast(idlicitacao as string) id_licitacao,
safe_cast(tiporegistro as string) tipo_registo,
safe_cast(anopedido as int64) ano_pedido,
safe_cast(numpedido as string) id_pedido,
safe_cast(
split(format_timestamp('%Y-%m-%d', timestamp(datahoracadastro)), ' ')[
safe_offset(0)
] as date
) data_cadastro,
safe_cast(
split(
format_timestamp('%Y-%m-%d %H:%M:%E*S', timestamp(datahoracadastro)), ' '
)[safe_offset(1)] as time
) horario_cadastro,
safe_cast(idorgao as string) id_orgao,
safe_cast(orgao as string) orgao,
safe_cast(objeto as string) descricao,
safe_cast(observacoes as string) observacao,
from `basedosdados-staging.br_camara_dados_abertos_staging.licitacao_pedido` as t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ config(alias="licitacao_proposta", schema="br_camara_dados_abertos") }}
select distinct
safe_cast(ano as int64) ano,
safe_cast(idlicitacao as string) id_licitacao,
safe_cast(descricao as string) descricao,
safe_cast(unidadeslicitadas as int64) quantidade_unidade_licitacao,
safe_cast(vlrestimado as int64) valor_estimado,
safe_cast(numproposta as string) id_proposta,
safe_cast(replace(unidadesproposta, ".0", "") as int64) unidade_proposta,
safe_cast(vlrproposta as int64) valor_proposta,
safe_cast(marcaproposta as string) marca_proposta,
safe_cast(fornecedorcpfcnpj as string) cpf_cnpj_fornecedor,
safe_cast(fornecedorsituacao as string) fornecedor_situacao,
safe_cast(dataproposta as date) data_proposta,
safe_cast(diasvalidadeproposta as int64) validade_proposta,
from `basedosdados-staging.br_camara_dados_abertos_staging.licitacao_proposta` as t
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ config(alias="orgao", schema="br_camara_dados_abertos") }}
select
regexp_extract(uri, r'/orgaos/(\d+)') id_orgao,
safe_cast(nome as string) nome,
safe_cast(apelido as string) apelido,
safe_cast(sigla as string) sigla,
safe_cast(uri as string) url_orgao,
safe_cast(tipoorgao as string) tipo_orgao,
safe_cast(
split(format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(datainicio)), 'T')[
Expand Down
Loading
Loading