Hi @Khasim_1
Does SDP Offer Built-in "Schema Drift" Modes? (Underlying Auto Loader/streaming Engine Defaults)
There are inherent built-in schema evolution behaviors for both ingestion (read_files) and target table writes in Spark Structured Streaming:
1. Ingestion/Source side (read_files/Auto Loader)
When reading streams, schema evolution options are specified in the source reader rather than on the sink writer
SQL
-- In SDP SQL (Streaming Table definition)
CREATE OR REFRESH STREAMING TABLE bronze_events
AS SELECT
...
FROM STREAM read_files(
'/path/to/events',
format => 'json',
schemaEvolutionMode => 'addNewColumns' -- options: addNewColumns, rescue, failOnNewFields
)
Python
# In Python SDP, we specify the reader options in our streaming source
from pyspark import pipelines as dp
@dp.table(name="bronze_events")
def bronze_events():
return (
spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.schemaEvolutionMode", "addNewColumns") # Or 'rescue'
.load("/path/to/events")
)
2. Declarative target schema behavior
SDP target tables (Streaming Tables) have built-in schema evolution behavior for Delta Lake / target table schemas, which is different than the conventional df.writeStream.option( mergeSchema, "true"):
Using addNewColumns evolution mode on the source reader will automatically add new columns to the target Streaming Table schema
Existing historical records will have null values filled in for any new columns that were added to the source reader schema
In Explicit Schemas vs. Graceful Handling
Most production pipelines I've worked on that require heavy ingestion have a mix of schema evolution modes across the medallion layers. Common patterns include:
Bronze (raw ingestion): Schema evolution allowed (schemaEvolutionMode => 'rescue'), ingestion of loosely-typed data or unexpected schema drift captured in a '_rescued_data' field
Avoiding downstream pipeline failures due to unexpected schema changes in upstream systems (Kafka topics/JSON blobs)
Silver/Gold (business logic layer): Schema evolution disabled + explicit schema enforcement with safe typecasting
Do not pass SELECT to downstream tables; explicitly select columns from the bronze layer table
Use TRY_CAST rather than CAST to gracefully handle schema drift attempts by upstream pipelines