I have dataframe with below schema. I want all the columns including the nested fields should be sorted alphabetically. I want it in scala spark.
root
|-- metadata2: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute2: string (nullable = true)
| | |-- attribute1: string (nullable = true)
|-- metadata3: string (nullable = true)
|-- metadata1: struct (containsNull = true)
| |-- attribute2: string (nullable = true)
| |-- attribute1: string (nullable = true)
when I sort using schema.sortBy(_.name), I get below schema(the nested array and struct type fields are not sorted)
root
|-- metadata1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute2: string (nullable = true)
| | |-- attribute1: string (nullable = true)
|-- metadata2: struct (containsNull = true)
| |-- attribute2: string (nullable = true)
| |-- attribute1: string (nullable = true)
|-- metadata3: string (nullable = true)
The schema which I want is as below. (Even the columns inside the metadata1(ArrayType) and metadata2(StructType) should be sorted)
root
|-- metadata1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute1: string (nullable = true)
| | |-- attribute2: string (nullable = true)
|-- metadata2: struct (containsNull = true)
| |-- attribute1: string (nullable = true)
| |-- attribute2: string (nullable = true)
|-- metadata3: string (nullable = true)
Thanks in advance.