Riccardo Delegà
07/24/2023, 7:42 AMStructType(
[
StructField(
"id",
StringType(),
metadata={
"comment": "Comment for this field"
},
)
],
# other fields
)
I was hoping there is a way of adding a column to the metadata
dict to define a certain StructField
as a Delta Lake generated column. Thanks for your help!Tom van Bussel
07/24/2023, 7:46 AMDeltaTableBuilder.addColumns
allows passing in a StructType
.DeltaColumnBuilder
API can be used, which exposes generatedAlwaysAs
and comment
. That way you don’t have to manually create the metadata.Riccardo Delegà
07/24/2023, 7:49 AMTom van Bussel
07/24/2023, 7:50 AMDeltaColumnBuilder
produces a StructField
if you call build
.Riccardo Delegà
07/24/2023, 7:52 AMTom van Bussel
07/24/2023, 7:54 AMRiccardo Delegà
07/24/2023, 7:59 AMDeltaColumnBuilder
API isn't exposed to Python, so I would probably have to pass through py4j to do this... I was asking if it carries over because if calling build
simply produces a StructField
with some additional metadata I could try creating it directly without passing through delta (which isn't a dependency of the project right now, as everything in that department is handled by DLT)delta.generationExpression
. It's documented here in the protocol definition. Thanks @Tom van Bussel for your help!