I am working on creating delta live table and I want to add columns based metadata comments.
Below is my code:
@dlt.table(
comment = "Flattened table for Student data",
name = 'Flattened_table'
)
def flatten():
df=spark.readStream.format("delta").load("url")
column_descriptions_dict={"colname1":"comment for colname 1", "colname2":"comment for
colname 2"}
for field in df.schema.fields:
df = df.withColumn(field.name, col(field.name).alias(field.name, metadata={"comment":
column_descriptions_dict[field.name]}))
return df
But once I check the dlt table , I do not see any comments(metadata) for my columns.
Does the dlt table not take pyspark metadata into consideration ?
You need to add the schema in
@dlt.tabledefinition like below:Then you will get the comments correctly.
Output: