I am trying to re-name a nested field within a Dataset of case classes using Spark 2.0. An example is as follows, where I am trying to rename "element" to "address" (maintaining where it is nested within the data structure):
df.printSchema
//Current Output:
root
|-- companyAddresses: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- addressLine: string (nullable = true)
| | |-- addressCity: string (nullable = true)
| | |-- addressCountry: string (nullable = true)
| | |-- url: string (nullable = true)
//Desired Output:
root
|-- companyAddresses: array (nullable = true)
| |-- address: struct (containsNull = true)
| | |-- addressLine: string (nullable = true)
| | |-- addressCity: string (nullable = true)
| | |-- addressCountry: string (nullable = true)
| | |-- url: string (nullable = true)
For reference, the following do not work:
df.withColumnRenamed("companyAddresses.element","companyAddresses.address")
df.withColumnRenamed("companyAddresses.element","address")