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: 

Delta Live Tables not inferring table schema properly.

BenLambert
Contributor

I have a delta live tables pipeline that is loading and transforming data. Currently I am having a problem that the schema inferred by DLT does not match the actual schema of the table. The table is generated via a groupby.pivot operation as follows:

 gb = (
        df.groupBy(['unique_trip_id', 'signal', 'value'])
        .count()
    )
    
    gb = (
         gb.groupBy(['unique_trip_id','value'])
        .pivot("signal")
        .sum("count")
        .fillna(0)
    )

I get the following error message:

org.apache.spark.sql.AnalysisException: A schema mismatch detected when writing to the Delta table (Table ID: fdecc1fa-fadd-4779-bc43-d93d87c9cc9e).

To enable schema migration using DataFrameWriter or DataStreamWriter, please set:

'.option("mergeSchema", "true")'.

For other operations, set the session configuration

spark.databricks.delta.schema.autoMerge.enabled to "true". See the documentation

specific to the operation for details.

My question is how can I set this option in my notebook for delta live tables? Or am I doing something wrong that is causing the schema inference to fail?

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions

BenLambert
Contributor

I was able to get around this by specifying the table schema in the table decorator.

View solution in original post

2 REPLIES 2

BenLambert
Contributor

I was able to get around this by specifying the table schema in the table decorator.

thank you for your reply. I will mark your response as best.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group