I have a dataframe with something like this df.printSchema:
root
|-- ts: timestamp (nullable = true)
|-- geoip: struct (nullable = true)
| |-- city: string (nullable = true)
| |-- continent: string (nullable = true)
| |-- location: struct (nullable = true)
| | |-- lat: float (nullable = true)
| | |-- lon: float (nullable = true)
I know that for example with df = df.withColumn("error", lit(null).cast(StringType)) I can add a null field called error of type string right under the root. How could I add the same field under the geoip struct, or under the location struct?
I have also tried df = df.withColumn("geoip.error", lit(null).cast(StringType)) with no luck.