Skip to content

Commit

Permalink
add new model dbt camara
Browse files Browse the repository at this point in the history
  • Loading branch information
tricktx committed Mar 1, 2024
1 parent d60e867 commit 0009a8c
Show file tree
Hide file tree
Showing 30 changed files with 750 additions and 300 deletions.
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
@@ -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(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,5 +1,6 @@
{{ 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ config(alias="orgao_deputado", schema="br_camara_dados_abertos") }}
select distinct
regexp_extract(uriorgao, r'/orgaos/(\d+)') as id_orgao,
safe_cast(nomeorgao as string) nome,
safe_cast(siglaorgao as string) sigla,
safe_cast(uriorgao as string) url,
safe_cast(nomedeputado as string) nome_deputado,
safe_cast(cargo as string) cargo,
safe_cast(siglauf as string) sigla_uf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

select
safe_cast(idproposicao as string) id_proposicao,
safe_cast(uriproposicao as string) url_proposicao,
replace(safe_cast(iddeputadoautor as string), ".0", "") id_deputado,
initcap(safe_cast(tipoautor as string)) tipo_autor,
initcap(safe_cast(nomeautor as string)) nome_autor,
safe_cast(uriautor as string) url_autor,
safe_cast(siglapartidoautor as string) sigla_partido,
upper(safe_cast(siglaufautor as string)) sigla_uf_autor,
safe_cast(uripartidoautor as string) url_partido,
safe_cast(ordemassinatura as string) ordem_assinatura,
safe_cast(proponente as string) proponente,
from `basedosdados-staging.br_camara_dados_abertos_staging.proposicao_autor` as t
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
materialized="table",
partition_by={
"field": "ano",
"data_type": "int64",
"range": {"start": 1935, "end": 2024, "interval": 1},
"data_type": "INT64",
"range": {"start": 1935, "end": 2023, "interval": 1},
},
)
}}
Expand All @@ -23,7 +23,7 @@ select
format_timestamp('%Y-%m-%dT%H:%M:%E*S', timestamp(dataapresentacao)), 'T'
)[offset(1)] as time
) horario,
safe_cast(id as string) id,
safe_cast(id as string) id_proposicao,
safe_cast(uri as string) url,
safe_cast(numero as string) numero,
safe_cast(siglatipo as string) sigla,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}}

select
safe_cast(ano as int64) ano,
safe_cast(uriproposicao as string) url_proposicao,
safe_cast(replace(ano, ".0", "") as int64) ano,
regexp_extract(uriproposicao, r'/proposicoes/(\d+)') as id_proposicao,
safe_cast(siglatipo as string) tipo_proposicao,
safe_cast(numero as string) numero,
safe_cast(codtema as string) tema,
Expand Down
Loading

0 comments on commit 0009a8c

Please sign in to comment.