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_tse_eleicoes #390

Merged
merged 18 commits into from
Feb 9, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
SELECT
{{
config(
schema='br_tse_eleicoes',
alias = 'bens_candidato',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2006,
"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(tipo_eleicao AS STRING) tipo_eleicao,
Expand All @@ -8,4 +26,4 @@ SAFE_CAST(id_tipo_item AS STRING) id_tipo_item,
SAFE_CAST(tipo_item AS STRING) tipo_item,
SAFE_CAST(descricao_item AS STRING) descricao_item,
SAFE_CAST(valor_item AS FLOAT64) valor_item
FROM basedosdados-staging.br_tse_eleicoes_staging.bens_candidato AS t
FROM basedosdados-staging.br_tse_eleicoes_staging.bens_candidato AS t
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'candidatos',
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(tipo_eleicao AS STRING) tipo_eleicao,
Expand Down Expand Up @@ -32,7 +50,7 @@ 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='N' THEN 'Não'
WHEN prestou_contas='S' THEN 'Sim'
END AS prestou_contas
FROM basedosdados-staging.br_tse_eleicoes_staging.candidatos AS t
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
SELECT
{{
config(
schema='br_tse_eleicoes',
alias = 'despesas_candidato',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2002,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
SAFE_CAST(tipo_eleicao AS STRING) tipo_eleicao,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'receitas_candidato',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2002,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(turno AS INT64) turno,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'receitas_comite',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2002,
"end": 2014,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf AS STRING) sigla_uf,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'receitas_orgao_partidario',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 2010,
"end": 2022,
"interval": 2
}
},
cluster_by=["sigla_uf"],
)
}}

SELECT
SAFE_CAST(ano AS INT64) ano,
SAFE_CAST(sigla_uf_diretorio AS STRING) sigla_uf,
Expand Down
35 changes: 35 additions & 0 deletions models/br_tse_eleicoes/br_tse_eleicoes__resultados_candidato.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'resultados_candidato',
materialized='table',
partition_by={
"field": "ano",
"data_type": "int64",
"range": {
"start": 1945,
"end": 2022,
"interval": 1
}
},
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_partido AS STRING) numero_partido,
SAFE_CAST(sigla_partido AS STRING) sigla_partido,
SAFE_CAST(numero_candidato AS STRING) numero_candidato,
SAFE_CAST(sequencial_candidato AS STRING) sequencial_candidato,
SAFE_CAST(id_candidato_bd AS STRING) id_candidato_bd,
SAFE_CAST(nome_candidato AS STRING) nome_candidato,
SAFE_CAST(resultado AS STRING) resultado,
SAFE_CAST(votos AS INT64) votos
FROM basedosdados-staging.br_tse_eleicoes_staging.resultados_candidato AS t
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'resultados_candidato_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(numero_partido AS STRING) numero_partido,
SAFE_CAST(sigla_partido AS STRING) sigla_partido,
SAFE_CAST(sequencial_candidato AS STRING) sequencial_candidato,
SAFE_CAST(numero_candidato AS STRING) numero_candidato,
SAFE_CAST(id_candidato_bd AS STRING) id_candidato_bd,
SAFE_CAST(votos AS INT64) votos
FROM basedosdados-staging.br_tse_eleicoes_staging.resultados_candidato_secao AS t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{
config(
schema='br_tse_eleicoes',
alias = 'resultados_partido_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(numero_partido AS STRING) numero_partido,
SAFE_CAST(sigla_partido AS STRING) sigla_partido,
SAFE_CAST(votos_nominais AS INT64) votos_nominais,
SAFE_CAST(votos_nao_nominais AS INT64) votos_nao_nominais
FROM basedosdados-staging.br_tse_eleicoes_staging.resultados_partido_secao AS t
Loading
Loading