Hi there :hand: I'm trying to create two tests: 1...
# community-support
a
Hi there ✋ I'm trying to create two tests: 1) a test that calculate anomalies for each column values count; 2) a test that calculate anomalies for the amount of distinct values of a column. Is this possible to implement using existing tests/tools? Thanks for your reply)
s
The best I've come up with is to create a second table with derived summary metrics and add columnar Elementary tests on the derived table. For example if I am trying to measure anomalies in
table_1
I'd create
table_1_derived_anomaly_detection_metrics
as something like
Copy code
{% set list_of_columns = [list here] %} 

select 
  date(timestamp) as dt,
  {% for col in column %}
  sum(case when {{col}} is not null then 1 else 0 end) as num_non_null_{{col}},
  count(distinct {{col}}) as num_distinct_val_{{col}}{%if not loop.last%},{% endif %}
  {% endfor%} 
from {{ ref('table_1') }}
group by 1
I'd then add elementary column
sum
tests for each of the relevant columns in
table_1_derived_anomaly_detection_metrics
a
Thanks for your advise!