basedosdados / queries-basedosdados

🔍 Gerenciador de modelos de transformação de dados (ELT) no datalake
8 stars 3 forks source link

Incluir possibilidade de usar o where no teste de dicionário #621

Closed laura-l-amaral closed 3 weeks ago

laura-l-amaral commented 1 month ago

tests:
    - custom_dictionary_coverage:
        columns_covered_by_dictionary: [id_verbete]
        dictionary_model: ref('br_bcb_estban__dicionario')
        config:
          where: __most_recent_year_month__
select
      count(*) as failures,
      count(*) != 0 as should_warn,
      count(*) != 0 as should_error
    from (

        with

            data_table_1 as (
                select id_verbete as id
                from (select * from `basedosdados-dev`.`br_bcb_estban`.`municipio` where ano = 2023 and mes = 12) dbt_subquery
                where id_verbete is not null
            ),
            dict_table_1 as (
                select chave
                from `basedosdados-dev`.`br_bcb_estban`.`dicionario`
                where valor is not null
                and id_tabela = "municipio"
                and nome_coluna = 'id_verbete'
            ),
            exceptions_1 as (
                select 'id_verbete' as failed_column, id as missing_value
                from data_table_1
                left join dict_table_1 on data_table_1.id = dict_table_1.chave
                where dict_table_1.chave is null
            )

        select distinct failed_column, missing_value from exceptions_1

    ) dbt_internal_test