Skip to content

fix(etl): flag multi-EIK authority rows so they don't form phantom authorities (#196) - #205

Closed
StanislavBG wants to merge 1 commit into
midt-bg:mainfrom
StanislavBG:fix/multi-eik-authority-rows
Closed

fix(etl): flag multi-EIK authority rows so they don't form phantom authorities (#196)#205
StanislavBG wants to merge 1 commit into
midt-bg:mainfrom
StanislavBG:fix/multi-eik-authority-rows

Conversation

@StanislavBG

Copy link
Copy Markdown
Contributor

What

Fixes #196 (conservative option — proposal 2).

~406 of ~4874 authority_eik values (~8%) are a list of several ЕИК joined by „; " — joint procurements where one notice names multiple co-authorities, e.g. 000590540; 000582020; 829091529 (source data/admin-tenders-load.sql:47202). In scripts/normalize-raw.sql step 1, keying 'auth:' || authority_eik on such a list minted one phantom authority for the whole list — a ЕИК that exists nowhere — and every downstream tender/contract/rollup then misattributed value to it.

Fix

Exclude list-valued rows from the authorities dedup:

WHERE authority_eik NOT LIKE '%;%'  -- exclude multi-ЕИК joint-procurement lists

Because tenders (2a/2b) and contracts (5) only attach to an authority that EXISTS in the authorities table, dropping the phantom node here transitively keeps those joint-procurement rows out of the served tenders/contracts and every rollup — no fake single authority, no misattributed value. The raw staging rows (raw_contracts/raw_tenders) are left untouched, so the joint procurements stay fully traceable for the follow-up.

Verification (real local D1, domain-only)

Applying the fix predicate to the produced authorities.bulstat (= authority_eik):

count
authorities before 4876
list-valued phantoms 405
kept after fix (single-ЕИК) 4471
dropped 405
legitimate single-ЕИК rows containing ; 0

Single-EIK authorities are unaffected; only the 405 phantom list nodes are removed.

Deferred (follow-up, proposal 1)

The full joint-procurement split — attributing a joint procurement to each real ЕИК (or a lead authority) without double-counting value in the totals — needs a product decision on how joint procurements are modelled, so it is intentionally not done here. A code comment in step 1 marks this deferral.

…thorities (midt-bg#196)

~406 of ~4874 authority_eik values are a list of several EIK joined by
"; " (joint procurements naming multiple co-authorities on one notice).
Keying 'auth:' || authority_eik on such a list minted one phantom
authority for the whole list. Exclude list-valued rows from the
authorities dedup (WHERE authority_eik NOT LIKE '%;%'); the tenders and
contracts EXISTS-on-authority guards then keep those joint-procurement
rows out of every served table and rollup. Raw staging is untouched, so
they stay traceable. Full joint-procurement split (proposal 1) is
deferred pending a product decision on modelling/value double-counting.
StanislavBG added a commit to StanislavBG/sigma-pr that referenced this pull request Jul 3, 2026
@StanislavBG

Copy link
Copy Markdown
Contributor Author

Superseded — folded into #203 (fix/authority-canonical-name), which now carries the canonical-name mode fix (#194) + the multi-ЕИК guard (#196) + the authority_eik indexes in one non-conflicting step-1 change. Closing to avoid the step-1 merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant