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

br_tse_eleicoes #534

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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,501 changes: 2,500 additions & 1 deletion metadata.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion models/br_tse_eleicoes/br_tse_eleicoes__bens_candidato.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"data_type": "int64",
"range": {"start": 2006, "end": 2022, "interval": 2},
},
cluster_by=["sigla_uf"],
)
}}

Expand Down
70 changes: 30 additions & 40 deletions models/br_tse_eleicoes/br_tse_eleicoes__candidatos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,35 @@
"data_type": "int64",
"range": {"start": 1994, "end": 2022, "interval": 2},
},
cluster_by=["sigla_uf"],
)
}}
-- precisa ser atualizada com as colunas de federação
select
safe_cast(ano as int64) ano,
safe_cast(tipo_eleicao as string) tipo_eleicao,
safe_cast(sigla_uf as string) sigla_uf,
safe_cast(id_municipio as string) id_municipio,
safe_cast(id_municipio_tse as string) id_municipio_tse,
cast(split(id_candidato_bd, '.')[offset(0)] as string) id_candidato_bd,
cast(split(cpf, '.')[offset(0)] as string) cpf,
safe_cast(titulo_eleitoral as string) titulo_eleitoral,
safe_cast(sequencial as string) sequencial,
safe_cast(numero as string) numero,
safe_cast(nome as string) nome,
safe_cast(nome_urna as string) nome_urna,
safe_cast(numero_partido as string) numero_partido,
safe_cast(sigla_partido as string) sigla_partido,
safe_cast(cargo as string) cargo,
safe_cast(situacao as string) situacao,
safe_cast(ocupacao as string) ocupacao,
safe_cast(data_nascimento as date) data_nascimento,
cast(split(idade, '.')[offset(0)] as int64) idade,
safe_cast(genero as string) genero,
safe_cast(instrucao as string) instrucao,
safe_cast(estado_civil as string) estado_civil,
safe_cast(nacionalidade as string) nacionalidade,
safe_cast(sigla_uf_nascimento as string) sigla_uf_nascimento,
safe_cast(municipio_nascimento as string) municipio_nascimento,
safe_cast(email as string) email,
safe_cast(raca as string) raca,
-- SAFE_CAST(situacao_totalizacao AS STRING) situacao_totalizacao,
-- SAFE_CAST(numero_federacao AS STRING) numero_federacao,
-- SAFE_CAST(nome_federacao AS STRING) nome_federacao,
-- SAFE_CAST(sigla_federacao AS STRING) sigla_federacao,
-- SAFE_CAST(composicao_federacao AS STRING) composicao_federacao,
-- CASE
-- WHEN prestou_contas='N' THEN 'Nao'
-- WHEN prestou_contas='S' THEN 'Sim'
-- END AS prestou_contas
from `basedosdados-staging.br_tse_eleicoes_staging.candidatos` as t

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
CAST(SPLIT(id_candidato_bd, '.')[OFFSET(0)] AS STRING) id_candidato_bd,
CAST(SPLIT(cpf, '.')[OFFSET(0)] AS STRING) cpf,
SAFE_CAST(titulo_eleitoral AS STRING) titulo_eleitoral,
SAFE_CAST(sequencial AS STRING) sequencial,
SAFE_CAST(numero AS STRING) numero,
SAFE_CAST(nome AS STRING) nome,
SAFE_CAST(nome_urna AS STRING) nome_urna,
SAFE_CAST(numero_partido AS STRING) numero_partido,
SAFE_CAST(sigla_partido AS STRING) sigla_partido,
SAFE_CAST(cargo AS STRING) cargo,
SAFE_CAST(situacao AS STRING) situacao,
SAFE_CAST(ocupacao AS STRING) ocupacao,
SAFE_CAST(data_nascimento AS DATE) data_nascimento,
CAST(SPLIT(idade, '.')[OFFSET(0)] AS INT64) idade,
SAFE_CAST(genero AS STRING) genero,
SAFE_CAST(instrucao AS STRING) instrucao,
SAFE_CAST(estado_civil AS STRING) estado_civil,
SAFE_CAST(nacionalidade AS STRING) nacionalidade,
SAFE_CAST(sigla_uf_nascimento AS STRING) sigla_uf_nascimento,
SAFE_CAST(municipio_nascimento AS STRING) municipio_nascimento,
SAFE_CAST(email AS STRING) email,
SAFE_CAST(raca AS STRING) raca
FROM basedosdados-staging.br_tse_eleicoes_staging.candidatos AS t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ select
"data_type": "int64",
"range": {"start": 2002, "end": 2022, "interval": 2},
},
cluster_by=["sigla_uf"],
)
}}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'detalhes_votacao_municipio',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1998,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(cargo AS STRING) cargo,
SAFE_CAST(aptos AS INT64) aptos,
SAFE_CAST(secoes AS INT64) secoes,
SAFE_CAST(secoes_agregadas AS INT64) secoes_agregadas,
SAFE_CAST(aptos_totalizadas AS INT64) aptos_totalizadas,
SAFE_CAST(secoes_totalizadas AS INT64) secoes_totalizadas,
SAFE_CAST(comparecimento AS INT64) comparecimento,
SAFE_CAST(abstencoes AS INT64) abstencoes,
SAFE_CAST(votos_validos AS INT64) votos_validos,
SAFE_CAST(votos_brancos AS INT64) votos_brancos,
SAFE_CAST(votos_nulos AS INT64) votos_nulos,
SAFE_CAST(votos_legenda AS INT64) votos_legenda,
SAFE_CAST(proporcao_comparecimento AS FLOAT64) proporcao_comparecimento,
SAFE_CAST(proporcao_votos_validos AS FLOAT64) proporcao_votos_validos,
SAFE_CAST(proporcao_votos_brancos AS FLOAT64) proporcao_votos_brancos,
SAFE_CAST(proporcao_votos_nulos AS FLOAT64) proporcao_votos_nulos
FROM basedosdados-staging.br_tse_eleicoes_staging.detalhes_votacao_municipio AS t
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'detalhes_votacao_municipio_zona',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1998,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(zona AS STRING) zona,
SAFE_CAST(cargo AS STRING) cargo,
SAFE_CAST(aptos AS INT64) aptos,
SAFE_CAST(secoes AS INT64) secoes,
SAFE_CAST(secoes_agregadas AS INT64) secoes_agregadas,
SAFE_CAST(aptos_totalizadas AS INT64) aptos_totalizadas,
SAFE_CAST(secoes_totalizadas AS INT64) secoes_totalizadas,
SAFE_CAST(comparecimento AS INT64) comparecimento,
SAFE_CAST(abstencoes AS INT64) abstencoes,
SAFE_CAST(votos_validos AS INT64) votos_validos,
SAFE_CAST(votos_brancos AS INT64) votos_brancos,
SAFE_CAST(votos_nulos AS INT64) votos_nulos,
SAFE_CAST(votos_legenda AS INT64) votos_legenda,
SAFE_CAST(proporcao_comparecimento AS FLOAT64) proporcao_comparecimento,
SAFE_CAST(proporcao_votos_validos AS FLOAT64) proporcao_votos_validos,
SAFE_CAST(proporcao_votos_brancos AS FLOAT64) proporcao_votos_brancos,
SAFE_CAST(proporcao_votos_nulos AS FLOAT64) proporcao_votos_nulos
FROM basedosdados-staging.br_tse_eleicoes_staging.detalhes_votacao_municipio_zona AS t
43 changes: 43 additions & 0 deletions models/br_tse_eleicoes/br_tse_eleicoes__detalhes_votacao_secao.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'detalhes_votacao_secao',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1994,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(zona AS STRING) zona,
SAFE_CAST(secao AS STRING) secao,
SAFE_CAST(cargo AS STRING) cargo,
SAFE_CAST(aptos AS INT64) aptos,
SAFE_CAST(comparecimento AS INT64) comparecimento,
SAFE_CAST(abstencoes AS INT64) abstencoes,
SAFE_CAST(votos_nominais AS INT64) votos_nominais,
SAFE_CAST(votos_brancos AS INT64) votos_brancos,
SAFE_CAST(votos_nulos AS INT64) votos_nulos,
SAFE_CAST(votos_coligacao AS INT64) votos_coligacao,
SAFE_CAST(votos_nulos_apu_sep AS INT64) votos_nulos_apu_sep,
SAFE_CAST(votos_pendentes AS INT64) votos_pendentes,
SAFE_CAST(proporcao_comparecimento AS FLOAT64) proporcao_comparecimento,
SAFE_CAST(proporcao_votos_nominais AS FLOAT64) proporcao_votos_nominais,
SAFE_CAST(proporcao_votos_coligacao AS FLOAT64) proporcao_votos_coligacao,
SAFE_CAST(proporcao_votos_brancos AS FLOAT64) proporcao_votos_brancos,
SAFE_CAST(proporcao_votos_nulos AS FLOAT64) proporcao_votos_nulos
FROM basedosdados-staging.br_tse_eleicoes_staging.detalhes_votacao_secao AS t
56 changes: 56 additions & 0 deletions models/br_tse_eleicoes/br_tse_eleicoes__partidos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'partidos',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1990,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(cargo AS STRING) cargo,
SAFE_CAST(numero AS STRING) numero,
SAFE_CAST(sigla AS STRING) sigla,
SAFE_CAST(nome AS STRING) nome,
SAFE_CAST(tipo_agremiacao AS STRING) tipo_agremiacao,
SAFE_CAST(sequencial_coligacao AS STRING) sequencial_coligacao,
SAFE_CAST(nome_coligacao AS STRING) nome_coligacao,
SAFE_CAST(composicao_coligacao AS STRING) composicao_coligacao,
SAFE_CAST(numero_federacao AS STRING) numero_federacao,
SAFE_CAST(nome_federacacao AS STRING) nome_federacacao,
SAFE_CAST(sigla_federacao AS STRING) sigla_federacao,
SAFE_CAST(composicao_federacao AS STRING) composicao_federacao,
SAFE_CAST(situacao_legenda AS STRING) situacao_legenda
FROM basedosdados-staging.br_tse_eleicoes_staging.partidos AS t

















Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'perfil_eleitorado_local_votacao',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2016,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(zona AS STRING) zona,
SAFE_CAST(secao AS STRING) secao,
SAFE_CAST(tipo_secao_agregada AS STRING) tipo_secao_agregada ,
SAFE_CAST(numero AS STRING) numero,
SAFE_CAST(nome AS STRING) nome,
SAFE_CAST(tipo AS STRING) tipo,
SAFE_CAST(endereco AS STRING) endereco,
SAFE_CAST(bairro AS STRING) bairro,
SAFE_CAST(cep AS STRING) cep,
SAFE_CAST(telefone AS STRING) telefone,
SAFE_CAST(latitude AS FLOAT64) latitude,
SAFE_CAST(longitude AS FLOAT64) longitude,
SAFE_CAST(situacao AS STRING) situacao,
SAFE_CAST(situacao_zona AS STRING) situacao_zona,
SAFE_CAST(situacao_secao AS STRING) situacao_secao,
SAFE_CAST(situacao_localidade AS STRING) situacao_localidade,
SAFE_CAST(situacao_secao_acessibilidade AS STRING) situacao_secao_acessibilidade,
SAFE_CAST(quantidade_eleitores AS INT64) quantidade_eleitores,
SAFE_CAST(quantidade_eleitores_eleicao AS INT64) quantidade_eleitores_eleicao,
FROM basedosdados-staging.br_tse_eleicoes_staging.perfil_eleitorado_local_votacao AS t
















Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'perfil_eleitorado_municipio_zona',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1998,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
SAFE_CAST(id_municipio AS STRING) id_municipio,
SAFE_CAST(id_municipio_tse AS STRING) id_municipio_tse,
SAFE_CAST(situacao_biometria AS STRING) situacao_biometria,
SAFE_CAST(zona AS STRING) zona,
SAFE_CAST(genero AS STRING) genero,
SAFE_CAST(estado_civil AS STRING) estado_civil,
SAFE_CAST(grupo_idade AS STRING) grupo_idade,
SAFE_CAST(instrucao AS STRING) instrucao,
SAFE_CAST(eleitores AS STRING) eleitores,
SAFE_CAST(eleitores_biometria AS STRING) eleitores_biometria,
SAFE_CAST(eleitores_deficiencia AS STRING) eleitores_deficiencia
FROM basedosdados-staging.br_tse_eleicoes_staging.perfil_eleitorado_municipio_zona AS t
















Loading