Hey @Panda ,
That will work but when you want to do this for each of the columns in your table it becomes very unclean in comparison to using something like the StructField Metadata attribute.
At the moment you would end up doing somethings like:
def _create_tags_script(self, column_name, field_name, value):
return f"ALTER COLUMN {column_name} SET TAGS ('{field_name}' = '{value}')"
def get_sql_script(self, catalog_name, schema_name, table_name):
alter_table_script = f"ALTER TABLE {catalog_name}.{schema_name}.{table_name}"
output_sql_script = []
for schema_field in self.schema_fields:
if schema_field.source_field:
output_sql_script.append(
f"{alter_table_script} {self._create_tags_script(schema_field.column_name, 'source_field', schema_field.source_field)}"
)
if schema_field.legacy_field:
output_sql_script.append(
f"{alter_table_script} {self._create_tags_script(schema_field.column_name, 'legacy_field', schema_field.legacy_field)}"
)
if schema_field.comment:
output_sql_script.append(
f"{alter_table_script} ALTER COLUMN {schema_field.column_name} COMMENT '{schema_field.comment}'"
)
return output_sql_script
which is just a bit more messy than
StructType(
[
StructField(
"columnName1",
StringType(),
True,
metadata = {
'comment': "This is a comment"
}
),
StructField(
"columnName2",
StringType(),
True,
metadata = {
'comment': "This is a comment"
}
),
StructField(
"columnName3",
StringType(),
True,
metadata = {
'comment': "This is a comment"
}
)
]
)