How to define write Option in a DLT using Python?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 11:56 AM
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?
- Labels:
-
Delta
-
Delta Live Tables
-
DLT
-
Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 11:51 AM
I would like to share the following docs page https://docs.databricks.com/delta-live-tables/python-ref.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 05:25 AM
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.

