pyspark.sql.functions.sort_array(col, asc=True)[source]

Collection function: sorts the input array in ascending or descending order according to the natural ordering of the array elements. Null elements will be placed at the beginning of the returned array in ascending order or at the end of the returned array in descending order.

New in version 1.5.0.

colColumn or str

name of column or expression

ascbool, optional


>>> df = spark.createDataFrame([([2, 1, None, 3],),([1],),([],)], ['data'])
[Row(r=[None, 1, 2, 3]), Row(r=[1]), Row(r=[])]
>>>, asc=False).alias('r')).collect()
[Row(r=[3, 2, 1, None]), Row(r=[1]), Row(r=[])]