Skip to content

Feature/dim developer org type - #15

Merged
zuhdil merged 7 commits into
mainfrom
feature/dim-developer-org-type
May 22, 2026
Merged

Feature/dim developer org type#15
zuhdil merged 7 commits into
mainfrom
feature/dim-developer-org-type

Conversation

@zuhdil

@zuhdil zuhdil commented May 22, 2026

Copy link
Copy Markdown
Contributor

No description provided.

zuhdil added 7 commits May 22, 2026 04:35
Extends `_transform_delimited_dimension` so a dimension built from a
delimited string can attach columns from a secondary silver table via
a name match.  Backwards-compatible: existing configs without an
`enrich_from` block behave exactly as before.

The hook is reached by the new sentinel source expression `"ENRICHED"`
in `schema_map` — it returns the attached value (or `None` when no
secondary row matches).  Where multiple secondary rows share the same
match key the first occurrence wins; for the upcoming `dim_developer`
case this is analytically safe because `vin_developers.org_type` for
a given `org_name` always comes from the same `accounts` row.
Three extra unit tests lock in the behaviour the original suite left
implicit:

- "first wins" actually verified with two different values (the
  earlier test had identical values, so a last-wins refactor would
  have slipped through),
- a NULL `match_target` value on a secondary-table row is skipped
  rather than treated as a valid lookup key,
- an empty secondary table yields all-NULL enrichment without
  raising (realistic during a cold run before silver populates
  vin_developers).

A defensive guard now raises `ValueError` upfront when the
`enrich_from` config block is missing one of `table`,
`match_target`, or `attach`, instead of failing deep inside the
transform with a bare `KeyError`. Three more tests cover that.
`dim_developer` now carries a nullable `org_type` column populated
from `silver.vin_developers.org_type` (which is itself joined from
`accounts.vin_organisationtype` and cleaned of unresolved numeric
codes in the bronze→silver step).

Match is by `developer_name` ↔ `org_name`, not `accountid`, because
`dim_developer` is still sourced from the delimited string in
`vin_candidates.developersaggregated` — roughly 5% of names there
have no `accounts` row at all, and dropping them would orphan
`bridge_candidate_developer`.  Those names get `org_type = NULL`,
which the slide-in design accepts.

The non-trivial trade-off (name-keyed instead of FK-keyed) is
described inline on the config block and recapped in
`transformations/developers.py` for readers who never see the spec.
Smoke check on the freshly built gold DB:
- the column exists,
- at least a few hundred rows carry a non-NULL org_type,
- no row leaks a literal numeric Dataverse code (e.g. "5001") that
  silver's `transform_developers` was supposed to null out.

This guards both the new enrichment wiring and the existing silver
cleanup against a future change that accidentally bypasses it.
The downstream consumer (`dim_developer.org_type` in gold, added in
the same change set) name-matches into `silver.vin_developers.org_type`
and would surface a literal "5001" verbatim if this cleanup ever
got removed or moved.  Spell that out in-place so a future maintainer
deleting "dead code" sees the contract before deleting it.

Also leaves a pointer for the eventual `accountid`-keyed outrigger
restructure — the place this cleanup belongs once `dim_developer`
references `dim_organization` directly.
The previous form `dev[numeric_like.fillna(False)]` is equivalent
today because `_read_table` returns a default RangeIndex, but it
breaks silently if the helper is ever changed to set a non-trivial
index.  Align with the plan's `.loc` + `.dropna` form so the index
alignment is explicit and the assertion stays robust.
Purely cosmetic — line-length, brace placement, and parenthesization
tweaks across the three files touched by this branch.  No behaviour
change; `ruff check` was already clean before this commit.
@zuhdil
zuhdil merged commit 22dd375 into main May 22, 2026
1 check passed
@zuhdil
zuhdil deleted the feature/dim-developer-org-type branch May 22, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant