A new field appears in the JSON files
An Auto Loader stream ingests JSON order files. The source team adds a new field, coupon_code. The stream stops with an error about an unknown field. Is this a bug? How should the pipeline handle schema changes?
Think it through or sketch an answer first, then open the hint or the solution.
Show a hint
Check the default schema evolution mode, and what happens after a restart.
Show the solution
It is expected. With the default addNewColumns mode, Auto Loader stops the stream when it sees a new column and records the new schema; on restart the column is added. Run the stream under a job with retries so this is automatic. Values that do not fit the schema (for example a type change) go into the rescued data column instead of being lost, so monitor it.
Example (Python)
(spark.readStream.format('cloudFiles')
.option('cloudFiles.format', 'json')
.option('cloudFiles.schemaLocation', '/Volumes/main/raw/_schemas/orders')
.option('cloudFiles.schemaEvolutionMode', 'addNewColumns')
.load('/Volumes/main/raw/orders')
.writeStream
.option('checkpointLocation', '/Volumes/main/raw/_checkpoints/orders')
.toTable('main.bronze.orders'))
Common mistakes
- Turning off schema inference and reading everything as strings forever, which pushes the problem downstream.
- Ignoring the _rescued_data column, so type changes silently drop values.
How did you do? Your answer is saved in this browser and comes back for revision later.
Learn more
- Auto Loader in DepthSpark & Databricks
- Advanced Ingestion and StreamingDatabricks Advanced