Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Collection function: Returns a reversed string or an array with elements in reverse order. Supports Spark Connect.
For the corresponding Databricks SQL function, see reverse function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.reverse(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
The name of the column or an expression that represents the element to be reversed. |
Returns
pyspark.sql.Column: A new column that contains a reversed string or an array with elements in reverse order.
Examples
Example 1: Reverse a string
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('Spark SQL',)], ['data'])
df.select(dbf.reverse(df.data)).show()
+-------------+
|reverse(data)|
+-------------+
| LQS krapS|
+-------------+
Example 2: Reverse an array
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([([2, 1, 3],) ,([1],) ,([],)], ['data'])
df.select(dbf.reverse(df.data)).show()
+-------------+
|reverse(data)|
+-------------+
| [3, 1, 2]|
| [1]|
| []|
+-------------+