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
where
e o teste é filtrado é executado somente para a data informada;