From 4c3c3c882de5e27d8380372ce112c2afe5006208 Mon Sep 17 00:00:00 2001 From: Tudor Sitaru Date: Wed, 1 Apr 2026 16:18:52 +0100 Subject: [PATCH] fix(dim_school): infer phase from age range for independent schools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Independent schools have phase='Not applicable' in GIAS. Now infer phase from statutory age range: <=11 → Primary, >=11 → Secondary, spans both → All-through. Falls back to original value if no age data. Co-Authored-By: Claude Opus 4.6 --- pipeline/transform/models/marts/dim_school.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pipeline/transform/models/marts/dim_school.sql b/pipeline/transform/models/marts/dim_school.sql index 9dead72..014acbe 100644 --- a/pipeline/transform/models/marts/dim_school.sql +++ b/pipeline/transform/models/marts/dim_school.sql @@ -14,7 +14,14 @@ select s.urn, s.local_authority_code * 1000 + s.establishment_number as laestab, s.school_name, - s.phase, + case + when s.phase is not null and s.phase != 'Not applicable' then s.phase + when s.statutory_high_age is not null and s.statutory_high_age <= 11 then 'Primary' + when s.statutory_low_age is not null and s.statutory_low_age >= 11 then 'Secondary' + when s.statutory_low_age is not null and s.statutory_high_age is not null + and s.statutory_low_age < 11 and s.statutory_high_age > 11 then 'All-through' + else s.phase + end as phase, s.school_type, s.academy_trust_name, s.academy_trust_uid,