Sub topic 4
Bronze: land raw data and keep it replayable
This chapter assumes you know basic SQL, PySpark DataFrames, and the idea of Delta tables from the previous chapters. The bronze layer is the first Delta table layer in the medallion architecture. It holds data as it arrived from the source, plus a little metadata about how it arrived.
What bronze is for
Bronze has one job: capture source data safely so you can rebuild everything downstream. If a silver transformation has a bug, you fix the code and rerun it against bronze. You never need to ask the source system to send the data again.
That goal sets a few rules:
- Append only. New data is added. Existing rows are not updated or deleted.
- Keep the raw shape. Do not clean, cast, filter, or deduplicate. Those steps belong in silver.
- Add load metadata. Record when and where each row came from.
- Tolerate change. A new or malformed field in the source should not stop ingestion.
How data flows
The landing volume keeps the original files. The bronze table makes them queryable. Together they give you two places to recover from.
Metadata worth keeping
Add columns that explain each row's origin. Prefix them with an underscore so they are not confused with source fields.
| Column | Meaning | Typical source |
|---|---|---|
| `_ingested_at` | When the row was loaded | `current_timestamp()` |
| `_source_file` | File the row came from | `_metadata.file_path` |
| `_rescued_data` | Fields that did not fit the schema | Added by Auto Loader |
The next chapter shows how Auto Loader fills these in. For now, notice what they let you do.
Using the metadata
Check what each file contributed to bronze:
SELECT
_source_file,
COUNT(*) AS rows_loaded,
MIN(_ingested_at) AS first_loaded
FROM main.bronze.orders
GROUP BY _source_file
ORDER BY first_loaded DESC
LIMIT 20;Find rows whose fields did not match the expected schema:
SELECT _source_file, _rescued_data
FROM main.bronze.orders
WHERE _rescued_data IS NOT NULL
LIMIT 20;Rescued data is JSON text holding the values Auto Loader could not place in a column, for example a field with an unexpected type. The row still lands in bronze, and you decide in silver what to do with it.
Choosing column types
For file sources, bronze often stores fields loosely, sometimes as strings, so a bad value cannot fail the load. Typing happens in silver. With JSON, Auto Loader infers types by default, so a field that arrives as text one day and a number the next can end up in _rescued_data. Setting cloudFiles.inferColumnTypes to false keeps JSON fields as strings. That choice is a trade-off. Strings are safer to ingest but push all casting work to silver.
Replaying from bronze
Replay means rerunning a downstream step against the history in bronze. Because bronze is append-only, the same input produces the same silver result. That also depends on the silver step being idempotent, meaning a rerun gives the same result as a single run. The MERGE chapter covers how to build that.
Delta history also helps. Each append creates a table version, so you can inspect an earlier state:
DESCRIBE HISTORY main.bronze.orders;Time travel is not a substitute for bronze's design. Retention settings and VACUUM eventually remove old versions, but the rows themselves stay in the table.
Exercise
A silver job cast amount incorrectly for two weeks. A teammate suggests deleting the bad rows from bronze and re-ingesting. What should you do instead, and why?
Show answer
Leave bronze unchanged. Fix the silver cast, then rerun the silver transformation over the bronze data. Bronze is append-only and holds the raw values, so the corrected job reproduces the right silver output without touching or reloading the source.