I have a dataframe with the following schema:
root
|-- docnumber: string (nullable = true)
|-- event: struct (nullable = false)
| |-- data: struct (nullable = true)
|-- codevent: int (nullable = true)
I need to add a column inside event.data so that the schema would be like:
root
|-- docnumber: string (nullable = true)
|-- event: struct (nullable = false)
| |-- data: struct (nullable = true)
|-- codevent: int (nullable = true)
|-- needtoaddit: int (nullable = true)
I tried
-
dataframe.withColumn("event.data.needtoaddit", lit("added"))but it adds a column with name
event.data.needtoaddit -
dataframe.withColumn( "event", struct( $"event.*", struct( lit("added") .as("needtoaddit") ).as("data") ) )but it creates an ambiguous column named
event.dataand again I have a problem.
How can I make it work?