fix(destinations): school rows and the England reference are different grains
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m4s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 11s
PR Checks / Build Frontend (no push) (pull_request) Successful in 45s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 52s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 2m27s
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m4s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 11s
PR Checks / Build Frontend (no push) (pull_request) Successful in 45s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 52s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 2m27s
The annual DAG died with a BrokenPipeError from Meltano's log writer, which is several frames from the cause: target-postgres exited first and the tap saw its stdout close. The tap declared primary_keys = [urn, ...] while emitting urn=None for the national rows, and target-postgres turns primary_keys into a NOT NULL constraint. The first national row of the run failed the insert and took the loader with it. Every other tap in this repo keys on non-null columns. Carrying two grains in one stream was the actual mistake, so the fix is to separate them rather than paper over the null: four streams now, with ees_ks4/ks5_destinations_national carrying no urn column at all — a school identifier that is null in every row is a grain mismatch, not a column. The staging models split the same way and the national mart reads the new pair instead of filtering `where urn is null`. Verified against the live API: the school stream yields 135,240 rows over 4,508 schools with no duplicate keys, no null key columns and all 31,382 suppression sentinels intact; the national streams yield 30 and 33 rows with no urn column. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BvdDKvFFSZuMVDH5fEyTob
This commit is contained in:
1 parent
fb5a0928bd
commit
e236669fde
9 files changed
+242
-34
No files matched your search
@@ -22,8 +22,7 @@ select
|
||||
pupils,
|
||||
percentage,
|
||||
status
|
||||
from {{ ref('stg_ees_ks4_destinations') }}
|
||||
where urn is null
|
||||
from {{ ref('stg_ees_ks4_destinations_national') }}
|
||||
|
||||
union all
|
||||
|
||||
@@ -36,5 +35,4 @@ select
|
||||
pupils,
|
||||
percentage,
|
||||
status
|
||||
from {{ ref('stg_ees_ks5_destinations') }}
|
||||
where urn is null
|
||||
from {{ ref('stg_ees_ks5_destinations_national') }}
|
||||
@@ -47,6 +47,17 @@ sources:
|
||||
16-18 study leavers destinations. Same grain, same suppression
|
||||
caveat, and only institutions with post-16 provision appear.
|
||||
|
||||
- name: ees_ks4_destinations_national
|
||||
description: >
|
||||
England KS4 destination measures by pupil group. A separate table
|
||||
from ees_ks4_destinations because it is a separate grain — no school,
|
||||
so no urn column. Same 'c' suppression caveat.
|
||||
|
||||
- name: ees_ks5_destinations_national
|
||||
description: >
|
||||
England 16-18 destination measures by pupil group. Same grain and
|
||||
caveat as ees_ks4_destinations_national.
|
||||
|
||||
- name: ees_ks4_performance
|
||||
description: KS4 performance tables (long format — one row per school × breakdown × sex)
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{{ config(materialized='table') }}
|
||||
|
||||
-- Staging model: KS4 leavers destinations, school level plus the England
|
||||
-- reference (which carries a null urn).
|
||||
-- Staging model: KS4 leavers destinations, school level.
|
||||
--
|
||||
-- School rows only. The England reference is a different grain and lives in
|
||||
-- stg_ees_ks4_destinations_national.
|
||||
--
|
||||
-- DELIBERATELY DOES NOT USE safe_numeric. That macro maps every EES sentinel
|
||||
-- (z, c, x, q, u) to NULL, which is right for attainment — there, "suppressed"
|
||||
@@ -14,13 +16,12 @@
|
||||
|
||||
with source as (
|
||||
select * from {{ source('raw', 'ees_ks4_destinations') }}
|
||||
-- National rows carry a null urn and feed fact_destination_national.
|
||||
where (urn is null or urn = '' or urn ~ '^[0-9]+$')
|
||||
where urn ~ '^[0-9]+$'
|
||||
and time_period ~ '^[0-9]+$'
|
||||
)
|
||||
|
||||
select
|
||||
case when urn ~ '^[0-9]+$' then cast(trim(urn) as integer) end as urn,
|
||||
cast(trim(urn) as integer) as urn,
|
||||
cast(trim(time_period) as integer) as year,
|
||||
trim(pupil_group) as pupil_group,
|
||||
trim(destination_measure) as destination_measure,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{{ config(materialized='table') }}
|
||||
|
||||
-- Staging model: England KS4 destination measures — the national
|
||||
-- reference the school sections compare against.
|
||||
--
|
||||
-- A separate model because it is a separate grain: there is no school here, and
|
||||
-- carrying these rows in the school table meant a null urn inside the primary
|
||||
-- key, which the Postgres loader rejects.
|
||||
--
|
||||
-- DELIBERATELY DOES NOT USE safe_numeric, for the same reason as the school
|
||||
-- model: 'suppressed' and 'not applicable' are different claims.
|
||||
|
||||
with source as (
|
||||
select * from {{ source('raw', 'ees_ks4_destinations_national') }}
|
||||
where time_period ~ '^[0-9]+$'
|
||||
)
|
||||
|
||||
select
|
||||
cast(trim(time_period) as integer) as year,
|
||||
trim(pupil_group) as pupil_group,
|
||||
trim(destination_measure) as destination_measure,
|
||||
|
||||
case when cohort_pupils ~ '^[0-9]+$'
|
||||
then cast(cohort_pupils as integer) end as cohort_pupils,
|
||||
|
||||
case when pupils_raw ~ '^[0-9]+$'
|
||||
then cast(pupils_raw as integer) end as pupils,
|
||||
|
||||
case when percentage_raw ~ '^-?[0-9]+(\.[0-9]+)?$'
|
||||
then cast(percentage_raw as numeric) end as percentage,
|
||||
|
||||
case
|
||||
when pupils_raw ~ '^[0-9]+$' then 'published'
|
||||
when lower(trim(pupils_raw)) = 'c' then 'suppressed'
|
||||
else 'not_applicable'
|
||||
end as status
|
||||
|
||||
from source
|
||||
@@ -1,8 +1,10 @@
|
||||
{{ config(materialized='table') }}
|
||||
|
||||
-- Staging model: 16-18 study leavers destinations, institution level plus the
|
||||
-- England reference (which carries a null urn). Only sixth forms and colleges
|
||||
-- appear here, so a secondary with no post-16 provision has no rows at all.
|
||||
-- Staging model: 16-18 study leavers destinations, institution level.
|
||||
--
|
||||
-- Only sixth forms and colleges appear, so a secondary with no post-16
|
||||
-- provision has no rows at all. The England reference is a different grain and
|
||||
-- lives in stg_ees_ks5_destinations_national.
|
||||
--
|
||||
-- DELIBERATELY DOES NOT USE safe_numeric. That macro maps every EES sentinel
|
||||
-- (z, c, x, q, u) to NULL, which is right for attainment — there, "suppressed"
|
||||
@@ -15,13 +17,12 @@
|
||||
|
||||
with source as (
|
||||
select * from {{ source('raw', 'ees_ks5_destinations') }}
|
||||
-- National rows carry a null urn and feed fact_destination_national.
|
||||
where (urn is null or urn = '' or urn ~ '^[0-9]+$')
|
||||
where urn ~ '^[0-9]+$'
|
||||
and time_period ~ '^[0-9]+$'
|
||||
)
|
||||
|
||||
select
|
||||
case when urn ~ '^[0-9]+$' then cast(trim(urn) as integer) end as urn,
|
||||
cast(trim(urn) as integer) as urn,
|
||||
cast(trim(time_period) as integer) as year,
|
||||
trim(pupil_group) as pupil_group,
|
||||
trim(destination_measure) as destination_measure,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{{ config(materialized='table') }}
|
||||
|
||||
-- Staging model: England KS5 destination measures — the national
|
||||
-- reference the school sections compare against.
|
||||
--
|
||||
-- A separate model because it is a separate grain: there is no school here, and
|
||||
-- carrying these rows in the school table meant a null urn inside the primary
|
||||
-- key, which the Postgres loader rejects.
|
||||
--
|
||||
-- DELIBERATELY DOES NOT USE safe_numeric, for the same reason as the school
|
||||
-- model: 'suppressed' and 'not applicable' are different claims.
|
||||
|
||||
with source as (
|
||||
select * from {{ source('raw', 'ees_ks5_destinations_national') }}
|
||||
where time_period ~ '^[0-9]+$'
|
||||
)
|
||||
|
||||
select
|
||||
cast(trim(time_period) as integer) as year,
|
||||
trim(pupil_group) as pupil_group,
|
||||
trim(destination_measure) as destination_measure,
|
||||
|
||||
case when cohort_pupils ~ '^[0-9]+$'
|
||||
then cast(cohort_pupils as integer) end as cohort_pupils,
|
||||
|
||||
case when pupils_raw ~ '^[0-9]+$'
|
||||
then cast(pupils_raw as integer) end as pupils,
|
||||
|
||||
case when percentage_raw ~ '^-?[0-9]+(\.[0-9]+)?$'
|
||||
then cast(percentage_raw as numeric) end as percentage,
|
||||
|
||||
case
|
||||
when pupils_raw ~ '^[0-9]+$' then 'published'
|
||||
when lower(trim(pupils_raw)) = 'c' then 'suppressed'
|
||||
else 'not_applicable'
|
||||
end as status
|
||||
|
||||
from source
|
||||
Reference in new issue
Block a user