I try to decompose the structure of a complex dataframe in spark. I am only interested in the nested arrays under the root. The issue is that I can't retrieve the ElementType from the type of StructField.
Here is an example, this schema of a StructType Object :
df.printSchema
result>>
root
|-- ID: string (nullable = true)
|-- creationDate: string (nullable = true)
|-- personsList: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- firstName: string (nullable = true)
| | |-- lastName: string (nullable = true)
Every StructType is an array of
FieldType ( name, type, nullable , metadata).
I tried the code below :
val personsList = df.schema("personsList") // personsList is a StructField
println(passengersList.dataType)
I would like to retrieve the ElementType to have the StructType of the nested array, but unfortunately we only have typeName or json method.
Best regards,