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.
Returns a sort expression for the target column in ascending order. This function is used in sort and orderBy functions. Supports Spark Connect.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.asc(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Target column to sort by in the ascending order. |
Returns
pyspark.sql.Column: The column specifying the sort order.
Examples
Example 1: Sort DataFrame by 'id' column in ascending order.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(4, 'B'), (3, 'A'), (2, 'C')], ['id', 'value'])
df.sort(dbf.asc("id")).show()
+---+-----+
| id|value|
+---+-----+
| 2| C|
| 3| A|
| 4| B|
+---+-----+
Example 2: Use asc in orderBy function to sort the DataFrame.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(4, 'B'), (3, 'A'), (2, 'C')], ['id', 'value'])
df.orderBy(dbf.asc("value")).show()
+---+-----+
| id|value|
+---+-----+
| 3| A|
| 4| B|
| 2| C|
+---+-----+