pyspark.sql.functions.
reverse
Collection function: returns a reversed string or an array with reverse order of elements.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
name of column or expression
array of elements in reverse order.
Examples
>>> df = spark.createDataFrame([('Spark SQL',)], ['data']) >>> df.select(reverse(df.data).alias('s')).collect() [Row(s='LQS krapS')] >>> df = spark.createDataFrame([([2, 1, 3],) ,([1],) ,([],)], ['data']) >>> df.select(reverse(df.data).alias('r')).collect() [Row(r=[3, 1, 2]), Row(r=[1]), Row(r=[])]