1. University MCA (AI/ML) Semester 2
  2. CAB206
  3. Unit 2

CAB206 · Unit 2: Data warehousing and ETL

ETL, ELT and slowly changing dimensions

8 practice questions

Key points

  • ETL transforms before load; ELT transforms inside the target
  • Incremental load uses watermark or CDC
  • Idempotent loads use upsert so reruns do not duplicate
  • SCD1 overwrite, SCD2 new row with history, SCD3 previous-value column
  • Type 2 preserves history for accurate historical reporting

ETL = Extract, Transform, Load. Data is extracted from sources, transformed (cleaned, deduplicated, conformed, keys looked up, aggregated) in a separate engine or staging area, then loaded into the warehouse. ELT loads raw data into the target (a cloud warehouse or lake) first and transforms it there using the target's compute; it suits scalable platforms and keeps raw data for reprocessing.

Load strategies

  • Full load: reload everything. Simple but slow.
  • Incremental load: load only new or changed rows, found by a watermark (last timestamp or id processed) or change data capture (CDC) from the source log.
  • Idempotent jobs give the same result if run twice. Use upsert/merge or replace-by-partition so a retry after failure does not duplicate rows.
  • Keep reject/error tables and logs for rows that fail validation.

Slowly changing dimensions (SCD) handle dimension attributes that change over time (a customer moves city).

  • Type 0: retain the original value; never change.
  • Type 1: overwrite the old value. No history. Past facts are restated under the new value.
  • Type 2: add a new row with a new surrogate key, with effective start/end dates and a current flag. Full history; facts keep pointing at the version valid when they happened.
  • Type 3: add a column for the previous value (current_city, previous_city). Limited history.
  • Type 6: a hybrid of 1, 2 and 3.

Choose Type 2 when reports must show facts under the attribute value true at the time.

Try two questions

Question 1 · Tier 3, Apply

A customer moved from Delhi to Pune to Mumbai. Sales of 500, 300 and 200 happened while they lived in each city respectively. Under SCD Type 1, a 'sales by city' report shows:

  1. Delhi 500, Pune 300 and Mumbai 200, the same as under Type 2
  2. Delhi 1,000, because the first city keeps all later sales
  3. Mumbai 1,000 and nothing for Delhi or Pune
  4. Pune 1,000, because the middle city keeps all of the sales
Show the answer

C. Type 1 overwrote the city with Mumbai, so all three sales are restated under Mumbai. Type 2 would give 500, 300 and 200 by city.

Question 2 · Tier 2, Understand

Slowly changing dimension Type 2 preserves history by:

  1. Adding a new row, with effective dates and a current flag, for each change
  2. Storing only the single previous value in one extra column
  3. Deleting all older fact rows whenever the attribute value changes
  4. Overwriting the existing row and discarding the old value entirely
Show the answer

A. Type 2 inserts a new version row with its own surrogate key, so old facts still point to the old version.