跳到正文

第 15 课 · Loading Data

ETL and ELT

Compare ETL and ELT, learn the steps of a warehouse load, route bad rows to a reject table, order dimension and fact jobs, and make pipelines repeatable.

A warehouse is only as good as the process that fills it. That process has three basic jobs: extract data from sources, transform it into the warehouse's shape, and load it. The order of the last two gives the two familiar names, ETL and ELT.

The two orders

ETL ELT
Order Transform before loading Load raw data, then transform inside the platform
Where transforms run A separate processing tool or server The warehouse or lakehouse engine
Raw data in the warehouse Often not kept Usually kept in staging
Often suits Strict filtering before data arrives, limited target capacity Scalable analytical platforms and SQL-based teams

Many real pipelines mix both. For example, you might mask a sensitive field before loading it, then do all other work with SQL afterwards. If the law or your policy says a value must never reach the warehouse, it has to be removed or protected before the load. "Load everything first" is not a safe default for sensitive data. See also ETL vs ELT in data engineering.

Extraction

Common ways to get data out of sources:

  • Full extract: copy the whole table. Simple and reliable for small tables.
  • Incremental extract: copy only new or changed rows.
  • Change data capture (CDC): read changes as they happen.
  • Files or APIs delivered by the source or a partner.

Respect the source. Large extracts can slow production systems, so agree on timing and access with its owner, and give the pipeline only the permissions it needs.

Transformation steps

Typical transformation steps

Clean Types, spaces, formats
Validate Rules and rejects
1 / 2

Do not lose bad rows silently

When a row fails a rule, you need a policy. You might stop the load, accept the row with a warning, or set it aside in a reject (quarantine) table with the reason. Whatever you choose, every input row should be accounted for.

SQL Validate, load and quarantine

Press Run (or Ctrl + Enter) to see the result here.

The final query shows that 5 rows in equal 2 loaded plus 3 rejected. This simple number check is a reconciliation.

The number test here is deliberately simple: it would accept text such as 1.2.3. Production pipelines should use the stricter conversion functions of their platform. Notice too that a negative amount might be a valid refund in your business. Validation rules must come from people who know the data.

Reject tables only help if someone looks at them. Give them an owner and an alert, and remember that they may contain sensitive data.

Order of jobs

Jobs depend on each other. A common order is:

  1. Load staging.
  2. Load or update dimensions.
  3. Load facts, looking up dimension keys.
  4. Build aggregates and marts.
  5. Run checks, then make the new data visible.

An orchestrator such as Apache Airflow runs these steps as a graph of dependencies, retries failures and records what happened. See orchestration and DAGs.

Make runs repeatable

Jobs fail: a network drops or a source sends a broken file. Design every step so that running it again is safe.

  • Identify each batch and the period it covers.
  • Replace a slice, or insert only what is missing, instead of blindly appending.
  • Use transactions or staged swaps so readers do not see half-loaded data.
  • Take the run date as a parameter rather than "today", so you can reprocess history.

Reprocessing earlier periods is called a backfill.

Tools

You can build transformations with plain SQL scripts, with SQL-based frameworks such as dbt, with general code, or with visual integration tools. Whatever you pick, keep the logic in version control, review changes, and test them on non-production data. Keep passwords and keys in a secret manager, never in scripts.

Idempotent steps by design

Different layers suit different rerun strategies:

Step A safe approach
Landing files Record each file's name and checksum, and skip files already loaded
Staging tables Replace the batch identified by its batch ID
Dimensions Compare with current rows, then update or add versions
Transaction facts Replace a complete time slice, or upsert on the grain
Aggregates Rebuild the affected periods from the detail

Plain INSERT without any of these protections is a common cause of doubled revenue after a retry.

When the source changes shape

Sources change: a column is renamed, a number turns into text or a new status code appears. Decide how the pipeline reacts. A new unused column can usually be accepted and recorded. A missing required column or an incompatible type should stop the load with a clear message. Avoid SELECT * in transformations that feed stable tables, because the output can then change shape without anyone choosing it.

Log what happened

For every run, record at least the job name, the batch or period, start and end times, rows read, rows written, rows rejected and the final status. With this small audit table you can answer "Was yesterday loaded?" and "When did the volume change?" without searching long text logs. Do not write passwords or personal data into logs. They are often visible to more people than the data itself.

Common mistakes

A pipeline that finishes without errors is not necessarily correct. It might have loaded zero rows, or the same day twice. Check row counts, totals and freshness, not only the job status.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What is the defining feature of ELT?

    The target engine does the transformation after raw data arrives.
  2. 2. A policy says a sensitive value must never reach the warehouse. What should the pipeline do?

    Protection has to happen before the data arrives.
  3. 3. Why use a reject table with reasons?

    Nothing disappears silently, and people can act on the reasons.
  4. 4. Which usually comes first?

    Fact loads need dimension keys to exist.

Summary

  • ETL transforms before loading; ELT loads first and transforms in the platform.
  • Protect sensitive data before it arrives when your rules require it.
  • Account for every row with reject handling and reconciliation.
  • Order jobs by dependencies and make each safe to rerun.

Next: Incremental Loads and Change Data Capture

你的学习进度保存在此浏览器中,无需账号。