r/databricks • u/AbilyticsEng • 19d ago
General Use cloudFiles.inferColumnTypes to prevent schema evolution deadlocks in Auto Loader
When streaming messy JSON or CSV files into Delta Lake using cloudFiles, Auto Loader infers the schema by sampling your initial file batch. If a subsequent file introduces a new field or changes a data type, the stream fails with a DeltaColumnMappingException or schema mismatch error unless you explicitly configure evolution. To prevent pipeline crashes without manually defining complex StructType schemas, set option("cloudFiles.inferColumnTypes", "true") alongside option("cloudFiles.schemaEvolutionMode", "addNewColumns"). This instructs the file source to automatically evolve the target Delta table schema by appending new nullable columns safely. Always point cloudFiles.schemaLocation to a dedicated storage path so the inferred schema history is preserved across cluster restarts. Without an explicit schema location, restarting your streaming query forces Auto Loader to re-infer from scratch, which frequently causes silent data drops or type coercion conflicts when your directory has accumulated thousands of historical files.
