feat(dbt): dim_school.inspectorate and ofsted_listed (H4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cc135ec58
commit
8e82e2e4cf
6 files changed
+101
-7
No files matched your search
@@ -1,9 +1,10 @@
|
||||
-- Mart: Canonical school dimension — one row per active URN
|
||||
|
||||
-- int_ofsted_latest is only ref()'d inside a conditional block below (it may not
|
||||
-- exist before the Ofsted pipeline first runs), so declare the dependency
|
||||
-- explicitly for dbt's DAG.
|
||||
-- int_ofsted_latest and int_ofsted_listed are only ref()'d inside conditional
|
||||
-- blocks below (they may not exist before the Ofsted pipeline first runs), so
|
||||
-- declare the dependencies explicitly for dbt's DAG.
|
||||
-- depends_on: {{ ref('int_ofsted_latest') }}
|
||||
-- depends_on: {{ ref('int_ofsted_listed') }}
|
||||
|
||||
with schools as (
|
||||
select * from {{ ref('stg_gias_establishments') }}
|
||||
@@ -15,6 +16,12 @@ with schools as (
|
||||
identifier='int_ofsted_latest'
|
||||
) %}
|
||||
|
||||
{% set listed_relation = adapter.get_relation(
|
||||
database=target.database,
|
||||
schema='intermediate',
|
||||
identifier='int_ofsted_listed'
|
||||
) %}
|
||||
|
||||
select
|
||||
s.urn,
|
||||
s.local_authority_code * 1000 + s.establishment_number as laestab,
|
||||
@@ -70,6 +77,14 @@ select
|
||||
s.status_code,
|
||||
s.nursery_provision,
|
||||
s.admissions_policy_code,
|
||||
-- The inspectorate GIAS names ("ISI" for most independent schools) and
|
||||
-- whether Ofsted's own data lists the school, inspected or not (audit H4).
|
||||
s.inspectorate_name as inspectorate,
|
||||
{% if listed_relation is not none %}
|
||||
l.urn is not null as ofsted_listed,
|
||||
{% else %}
|
||||
null::boolean as ofsted_listed,
|
||||
{% endif %}
|
||||
|
||||
-- Latest Ofsted (populated after monthly Ofsted pipeline runs). The grade
|
||||
-- still in force and the latest visit, from int_ofsted_latest — never a
|
||||
@@ -88,6 +103,9 @@ from schools s
|
||||
{% if ofsted_relation is not none %}
|
||||
left join {{ ref('int_ofsted_latest') }} o on s.urn = o.urn
|
||||
{% endif %}
|
||||
{% if listed_relation is not none %}
|
||||
left join {{ ref('int_ofsted_listed') }} l on s.urn = l.urn
|
||||
{% endif %}
|
||||
-- 1 = Open; 3 = Open, but proposed to close (still operating; drops out when
|
||||
-- GIAS flips to Closed — marts fully rebuild each run).
|
||||
where s.status_code in (1, 3)
|
||||
|
||||
Reference in new issue
Block a user