cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

LEGACY_ERROR_TEMP_DELTA_0007 A schema mismatch detected when writing to the Delta table.

shan-databricks
New Contributor II

Need help to resolve the issue 

Error : com.databricks.sql.transaction.tahoe.DeltaAnalysisException: [_LEGACY_ERROR_TEMP_DELTA_0007] A schema mismatch detected when writing to the Delta table.

I am using the below code and my JSON is dynamically changing daily basis

(spark.readStream
              .format("cloudFiles")
              .option("cloudFiles.format", "json")
              .option("header", "true")
              .option("cloudFiles.inferColumnTypes", "true")
              .option("cloudFiles.schemaLocation", schema_location)
              .load(input_path)
              .writeStream.format("delta")
              .option("checkpointLocation", checkpoint_location)
              .trigger(availableNow=True)
              .partitionBy(*partition_columns)
              .option("mergeSchema", "true")
              .option("badRecordsPath", f"{checkpoint_location}/badRecords")
              .option("overwriteSchema", "true")
              .option("schemaEvolutionMode", "addNewColumns")
              .outputMode("append")
              .start(output_path))

 

1 REPLY 1

cgrant
Databricks Employee
Databricks Employee

For datasets with constantly changing schemas, we recommend using the Variant type.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now