From 951c666f8ac2f8e7655654546c2444761c685d65 Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 6 Oct 2026 12:50:27 +0100 Subject: [PATCH] test(dbt): warn when DfE's LA averages fall behind the school results (review) Co-Authored-By: Claude Opus 5.5 --- .../tests/assert_ks4_la_averages_current.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pipeline/transform/tests/assert_ks4_la_averages_current.sql diff --git a/pipeline/transform/tests/assert_ks4_la_averages_current.sql b/pipeline/transform/tests/assert_ks4_la_averages_current.sql new file mode 100644 index 0000000..ddd914c --- /dev/null +++ b/pipeline/transform/tests/assert_ks4_la_averages_current.sql @@ -0,0 +1,20 @@ +{{ config(severity='warn') }} + +-- DfE's LA averages cover the latest year with school results. They come from +-- a fixed EES data set (ks4_summary.KS4_SUMMARY_CSV_URL); when DfE publishes a +-- new year under a new data set, the school results move on and this mart does +-- not, so /api/la-averages serves an empty map and every "vs LA avg" goes. +-- A warning, not an error: it must not hold back a new year's school results. + +with schools as ( + select max(year) as year from {{ ref('stg_ees_ks4') }} where attainment_8_score is not null +), + +las as ( + select max(year) as year from {{ ref('fact_ks4_la_averages') }} +) + +select s.year as latest_school_year, l.year as latest_la_year +from schools s +cross join las l +where l.year is null or l.year < s.year