This is a dummy sample of my dataframe
data = [
[3273, "city y", [["ids", 27], ["smf", 13], ["tlk", 35], ["thr", 24]]],
[3213, "city x", [["smf", 23], ["tlk", 15], ["ids", 17], ["thr", 34]]],
]
df = spark.createDataFrame(
data, "city_id:long, city_name:string, cel:array<struct<carr:string, subs:int>>"
)
df.show(2, False)
+-------+---------+--------------------------------------------+
|city_id|city_name|cel |
+-------+---------+--------------------------------------------+
|3273 |city y |[[ids, 27], [smf, 13], [tlk, 35], [thr, 24]]|
|3213 |city x |[[smf, 23], [tlk, 15], [ids, 17], [thr, 34]]|
+-------+---------+--------------------------------------------+
I need to descendingly sort the array of column cel based on its subs value. It would be like this
+-------+---------+--------------------------------------------+
|city_id|city_name|cel |
+-------+---------+--------------------------------------------+
|3273 |city y |[[tlk, 35], [ids, 27], [thr, 24], [smf, 13]]|
|3213 |city x |[[thr, 34], [smf, 23], [ids, 17], [tlk, 15]]|
+-------+---------+--------------------------------------------+
Is there a way of doing it without using an UDF if possible? thanks
I am using spark version 2.4.0