pyspark.sql.functions.array_sort

pyspark.sql.functions.array_sort(col: ColumnOrName) → pyspark.sql.column.Column

Collection function: sorts the input array in ascending order. The elements of the input array must be orderable. Null elements will be placed at the end of the returned array.

Parameters
colColumn or str

name of column or expression

Examples

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