Consider the following dataframe:
case class ArrayElement(id:Long,value:Double)
val df = Seq(
Seq(
ArrayElement(1L,-2.0),ArrayElement(2L,1.0),ArrayElement(0L,0.0)
)
).toDF("arr")
df.printSchema
root
|-- arr: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- id: long (nullable = false)
| | |-- value: double (nullable = false)
Is there a way to sort arr by value other than using an udf?
I've seen org.apache.spark.sql.functions.sort_array, what is this method actually doing in the case of complex array elements? Is it sorting the array by the first element (i.e. id?)