Skip to main content
← Back to Patterns

Repair a Type 2 dimension when a correction changes the past

By Ivan Richter LinkedIn

Last updated:

8 min read

In brief

Repair a Type 2 dimension from the correction's effective date and revisit facts whose historical match changes.

  • Rebuild the affected intervals and check that each fact matches the intended version.
  • Publish the corrected dimension and dependent fact changes together.
On this page

An asset belongs to the north maintenance area from January, then the south area from April. In May, the source corrects the history. It belonged to central from 15 February until the April change.

Updating the current dimension row would change the wrong period. Appending central from May would preserve a history we now know is wrong.

For a dimension that promises corrected effective history, we’d reconstruct the affected asset’s interval sequence from its accepted source changes. Then we’d re-evaluate the facts whose historical attachment or derived attributes can change.

That recommendation assumes the output answers what was effective then, using the evidence accepted now. An output that must reproduce what a previous decision knew also needs recorded-time history or preserved results. One effective timeline can’t answer both questions.

Work out which statement the source is correcting

Is the source adding a late change or correcting an earlier one? The two need different input handling. A new assignment effective in February adds a boundary, a later revision saying that assignment began on 20 February moves it, and a retraction can remove it entirely.

Keep the source change identity, its revision or supersession evidence, effective date, full attribute state, and receipt evidence. The producer defines the ordering that picks the accepted revision, and arrival time is weak evidence when a connector can replay older messages.

Our example source sends complete maintenance assignments, effective at date granularity, with an ordered revision for each change identity. Before building intervals, we select the newest accepted revision of each change and remove authoritative retractions. A duplicate delivery of the same revision has no effect, but different payloads claiming the same identity and revision are a conflict.

Two distinct active changes for the same asset and effective date also need resolving before interval construction. If the source defines precedence, implement it. Otherwise hold the asset’s repair and expose the competing assertions. Breaking the tie by a random event ID would give the same arbitrary answer on every run.

A patch feed needs another step. Reconstruct complete state under its documented ordering and missing-field semantics. A future patch that changes only the area name doesn’t replace every earlier corrected attribute. With full-state input, each later assignment defines the next boundary cleanly, but copying that assumption into a patch feed would change the feed’s meaning.

Reconstruct the timeline around the correction

The accepted changes for asset A7 initially contain January’s north assignment and April’s south assignment. Adding the late February change should produce this candidate:

Effective fromEffective to, exclusiveArea
1 January15 FebruaryNorth
15 February1 AprilCentral
1 AprilUnboundedSouth

The February correction shortens January’s interval and adds a new one, while April remains intact. Rebuilding all accepted changes for this asset is usually easier to review than maintaining separate branches for corrections before, inside, and after every existing interval. The same construction handles a revised effective date or a retracted change.

For a very large entity history, you can bound the rebuild to the affected neighbors once the full reconstruction is a tested reference. Include the predecessor that gives state at the left boundary and the later changes that stop its propagation. A query filtered to newly received rows can’t close the old interval. It never sees that interval’s row.

With one accepted complete state per asset and effective date, the next start becomes the current row’s exclusive end:

SELECT
  asset_id,
  change_id,
  effective_from,
  LEAD(effective_from) OVER (
    PARTITION BY asset_id ORDER BY effective_from
  ) AS effective_to,
  maintenance_area
FROM accepted_changes;

LEAD returns null by default when no following row exists, in both PostgreSQL and BigQuery. Here that final null means an unbounded upper end. Downstream code must keep that meaning.

Selecting accepted source revisions and allocating warehouse surrogate keys happen outside this query. It needs non-null asset and start values, resolved equal-time conflicts, and complete attribute states.

The source might show that an asset stopped existing or an assignment ended without replacement. Record that termination in the timeline instead of extending the last observed active assignment forever. Here the unbounded final row is valid: the producer defines an assignment as effective until another accepted change.

Make interval boundaries executable

Use half-open intervals: a fact at the start belongs to the new row, and a fact exactly at the end belongs to the following row. BigQuery’s native RANGE type uses inclusive lower and exclusive upper bounds, and PostgreSQL range types can express the same convention.

The equivalent ordinary-column join is small enough to inspect:

SELECT f.fact_id, d.change_id, d.maintenance_area
FROM work_facts AS f
LEFT JOIN candidate_intervals AS d
  ON f.asset_id = d.asset_id
 AND f.work_date >= d.effective_from
 AND (f.work_date < d.effective_to OR d.effective_to IS NULL);

An inclusive BETWEEN against both endpoints can match two rows at a transition. Take five facts dated 10 January, 14 February, 15 February, 20 March, and 1 April, with respective costs of 10, 20, 30, 40, and 50.

The half-open join returns five attachments. The inclusive version returns seven: both boundary facts match twice. The total can inflate even though the dimension contains the expected three rows.

Check that each finite interval has a strictly later end and that intervals don’t overlap for an asset. Every fact in a scope that requires an assignment must match exactly one interval. Run these as three separate assertions. Intervals with unique asset/start pairs can still overlap, and non-overlapping intervals can still leave a fact uncovered.

Facts before the first known assignment are unresolved. Extending the first row backward invents history unless the source contract warrants it. A December fact stays unmatched until the source sends a December assignment. An unknown or withheld dimension member is more accurate than a plausible maintenance area.

Find the facts whose interpretation changed

Compare each affected asset’s facts against the old and new timelines. Include a fact when its match, attributes, or dependent calculation differs.

For the first correction, two example facts move from north to central: one on 15 February and one on 20 March. Their costs sum to 70. The January, 14 February, and 1 April facts keep their assignments.

Keep the fact’s original business key and event date available for that re-evaluation, in raw facts or another reliable mapping back to the original asset and date. A fact containing only the current surrogate reference can make repair much harder if the old row is removed before its source identity is recovered. If facts store a Type 2 surrogate key, allocate or reuse dimension keys under the model’s key contract, then update the affected references. Keep the keys of unchanged versions where possible. Recreating every dimension key on each run turns a small historical correction into an unnecessary rewrite of all dependent facts.

A join performed at query time avoids a stored key rewrite, but materialized aggregates or extracted reports can still hold the old interpretation. A corrected attribute may change a grouping without changing a stable source change ID. Compare the fields and relationships the output uses. Kimball covers this fact restatement under retroactive dimensional changes.

When the effective date moves from 15 to 20 February, repair the old range too. A filter starting at the new date would miss the 15 February fact that must return to north. Rebuilding and comparing the old and new entity histories avoids that blind spot.

Retraction has the same requirement. Removing central means the preceding assignment resumes until 1 April.

Fact counts and costs must survive reattachment. The repair changes which area each fact is attributed to and leaves the maintenance events alone.

If the business also wants a measure restated, treat that as a separate calculation change with its own controls.

An unchanged grand total is only one control. Before the correction, north has costs of 100 and south 50. Afterward, north has 30, central 70, and south still 50. Both versions sum to 150, so checking only the total would pass even if the repair never changed an attachment.

Keep expected results at the grain affected by the correction, including an unaffected neighboring period. That exposes both a missed repair and a broad accidental overwrite.

Moving central’s start to 20 February extends north through 19 February, and retracting central extends north until 1 April. South starts on 1 April in all three versions.

Work dateCostArea
10 January10North in all three versions
14 February20North in all three versions
15 February30Central when central starts 15 February, north otherwise
20 March40North when central is retracted, central otherwise
1 April50South in all three versions

After the move, north has 60, central 40, and south 50. After retraction, north has 100 and south 50. The total is 150 in all three.

Keep enough evidence to explain a changed attachment without rerunning the entire warehouse. For each repaired fact, keep the original asset and date, the previous dimensional version, the accepted replacement, and the source revision set.

The operational record should also name the derived outputs that were rebuilt. A dimension repair marked complete while its area-level aggregate still shows north’s old 100 leaves two contradictory answers in service.

Publish the dimension and fact repair together

Build the candidate dimension and its affected fact mapping before changing the served result. Validate intervals, match cardinality, and measure controls against the same accepted source revisions.

Readers need a consistent view of both replacements, so publish them together.

For a bounded repair in one database, a transaction can contain both the interval replacement and the fact-reference updates. In a test, interrupt that transaction after replacing the dimension but before updating links. Rollback must preserve the previous dimension and links together, and a successful commit must publish both.

Before releasing a repair, test a newly inserted boundary, a moved effective date, and a retraction, with an unaffected neighboring period as a control.

The examples here use source change IDs to make attachment visible. A production model also has to verify surrogate-key allocation and concurrent publication under its own key and release contracts.

Some consumers must know what the system believed on a previous date, or reproduce an answer issued earlier. For them, keep the recorded-time versions or the inputs to each issued result, as Fowler describes in effective and recorded history. Add that model only when a concrete consumer needs it. Attributes that only need their current state may not need Type 2 history at all.

More in this domain: Data

Browse all

Related patterns