Skip to content

Commit

Permalink
Trocar testes e Modificação do not_null_proportion_multiple_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Winzen committed Nov 22, 2024
1 parent bf16056 commit ff6bafa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 5 additions & 5 deletions models/br_tse_eleicoes/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ models:
- name: br_tse_eleicoes__bens_candidato
description: Declaração de bens de candidatos em eleições brasileiras.
tests:
- custom_not_null_proportion_multiple_columns:
- not_null_proportion_multiple_columns:
at_least: 0.70
ignore_values: [tipo_item, data_eleicao, id_eleicao]
columns:
Expand Down Expand Up @@ -43,8 +43,8 @@ models:
- name: br_tse_eleicoes__candidatos
description: Dados de candidatos em eleições brasileiras.
tests:
- custom_not_null_proportion_multiple_columns:
at_least: 0.80
- not_null_proportion_multiple_columns:
at_least: 0.05
ignore_values: [email, raca]
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
Expand Down Expand Up @@ -158,7 +158,7 @@ models:
- name: br_tse_eleicoes__despesas_candidato
description: Dados de despesas em campanhas eleitorais a nível de despesa.
tests:
- custom_not_null_proportion_multiple_columns:
- not_null_proportion_multiple_columns:
at_least: 0.05
ignore_values:
- esfera_partidaria_fornecedor
Expand Down Expand Up @@ -778,7 +778,7 @@ models:
- name: br_tse_eleicoes__receitas_candidato
description: Dados de financiamento de campanha de receita para candidatos.
tests:
- custom_not_null_proportion_multiple_columns:
- not_null_proportion_multiple_columns:
at_least: 0.05
ignore_values:
- descricao_cnae_2_doador_orig
Expand Down
27 changes: 20 additions & 7 deletions tests/generic/not_null_proportion_multiple_columns.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% test not_null_proportion_multiple_columns(model, at_least=0.05) %}
{% test not_null_proportion_multiple_columns(model, ignore_values="", at_least=0.05) %}

{%- set columns = adapter.get_columns_in_relation(model) -%}
{% set suffix = "_nulls" %}
Expand Down Expand Up @@ -28,8 +28,7 @@
*
from pivot_columns
where
quantity / total_records > (1 - {{ at_least }})

quantity / total_records > (1 - {{ at_least }}) and column_name not in ('{{ ignore_values | join("', '") }}')

)
select * from faulty_columns
Expand All @@ -41,16 +40,30 @@
) -%}
{% if errors["column_name"] != () %}
{% for e in errors["column_name"] | unique %}

{% set proc_err = (
errors["quantity"][loop.index0]
/ errors["total_records"][loop.index0]
) * 100 %}

{{
log(
"LOG: Coluna com preenchimento menor que "
~ at_least * 100
~ "% ---> "
"Coluna: "
~ e
~ " [FAIL]",
~ " - Quantidade: "
~ errors["quantity"][loop.index0]
~ " - Total: "
~ errors["total_records"][loop.index0]
~ " - Preenchimento: "
~ "%0.2f"
| format(proc_err | float)
~ " - Preenchimento ideal: "
~ at_least * 100
~ " - Resultado: FAIL",
info=True,
)
}}

select '{{e}}' as column
{% if not loop.last %}
union all
Expand Down

0 comments on commit ff6bafa

Please sign in to comment.