Hi. Could someone explain why Freshness tests have...
# community-support
a
Hi. Could someone explain why Freshness tests have anomaly sensitivity if we just need to calculate time between updates, not data volumne? Thanks
n
Hey, freshness anomaly tests search for anomalies in the time between updates - any row that's added to the table is considered an update 🙂
Also, I see that there are a few unclear things about Elementary - Feel free to try asking Elementary AI in the #C08HW57FGN9 channel 🙌
a
Ok, but why do I get an error when there is an spike or drop in data for freshness tests if only time between update matters?
image.png
there are 2 kind of tests
n
Can you please share a screenshot of the graph with the spikes?
a
1000296331.jpg
Any clues?
n
These are 12 hour buckets, correct?
a
Yes, I think so
Again, I don't care about volume of the data
n
This graph reflects the time between updates, it doesn't have anything to do with the volume 🙂 For every bucket (12 hours), the max amount of time between updates is the value of the bucket. Maybe smaller time buckets can provide better insights, and perhaps a seasonality feature because it seems like there's a pattern here. If an anomaly test doesn't fit your needs, maybe a more simple custom SQL test can be better for this case. Of course it will also show up in the Elementary UI.
a
Thanks!
🙌 1
@Noya Offer can we test singular or discrete points in time instead of buckets?
n
Maybe something like this would work better? Testing against a clear threshold:
Copy code
{% test freshness_not_stale(model, column_name, max_age_hours) %}

WITH latest_update AS (
    SELECT MAX({{ column_name }}) AS max_time
    FROM {{ model }}
),

check AS (
    SELECT
        max_time,
        CURRENT_TIMESTAMP AS current_time,
        DATETIME_DIFF(CURRENT_TIMESTAMP, max_time, MINUTE) AS minutes_diff
    FROM latest_update
)

SELECT *
FROM check
WHERE minutes_diff > {{ max_age_hours * 60 }}

{% endtest %}
It's the end of our workday and our weekend tomorrow, so I would highly recommend Elementary AI. It does great with generating tests to your needs 🙂