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: 

How to define write Option in a DLT using Python?

pablociu
New Contributor

In a normal notebook I would save metadata to my Delta table using the following code:

(
  df.write
    .format("delta")
    .mode("overwrite")
    .option("userMetadata", user_meta_data) 
    .saveAsTable("my_table")
)

But I couldn't find online how can I set up the '.option("userMetadata...' in a DLT. Is there a document I couldn't find that would explain how to set up this?

2 REPLIES 2

jose_gonzalez
Databricks Employee
Databricks Employee

I would like to share the following docs page https://docs.databricks.com/delta-live-tables/python-ref.html

United_Communit
New Contributor II

In Delta lab you can set up User MetaData so i will give you some tips

from delta import DeltaTable

# Create or load your Delta table

delta_table = DeltaTable.forPath(spark, "path_to_delta_table")

# Define your user metadata myccpay

user_meta_data = {"key1": "value1", "key2": "value2"}

# Set the userMetadata option in your Delta table write operation

delta_table.alias("df").merge(

  df.alias("new_data"),

  "df.id = new_data.id"

 ).whenMatchedUpdateAll()

 .whenNotMatchedInsertAll()

 .option("userMetadata", user_meta_data)

 .execute()

you should try this code.

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