cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Error when running OPTIMIZE on a Delta table with generated columns

620139
New Contributor II

I am seeing an error when running OPTIMIZE on a Delta table with generated columns:

com.databricks.sql.transaction.tahoe.schema.DeltaInvariantViolationException: CHECK constraint Generated Column (created <=> now()) violated by row with values:

 - created : 1672360020111000

Using a cluster with runtime 11.3 LTS (includes Apache Spark 3.3.0, Scala 2.12)

Any ideas how I can successfully OPTIMIZE this table?

3 REPLIES 3

Ajay-Pandey
Esteemed Contributor III

Have you applied any constraints on your table?

As it's giving errors for constraint 

620139
New Contributor II

It appears the constraint is related to the generated column:

https://docs.databricks.com/delta/generated-columns.html

"For example, you can automatically generate a date column (for partitioning the table by date) from the timestamp column; any writes into the table need only specify the data for the timestamp column. However, if you explicitly provide values for them, the values must satisfy the constraint (<value> <=> <generation expression>) IS TRUE or the write will fail with an error."

Anonymous
Not applicable

Hi @Jeff Erickson​ 

Thank you for your question! To assist you better, please take a moment to review the answer and let me know if it best fits your needs.

Please help us select the best solution by clicking on "Select As Best" if it does.

Your feedback will help us ensure that we are providing the best possible service to you.

Thank you!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.