zhengruifeng commented on code in PR #42717:
URL: https://github.com/apache/spark/pull/42717#discussion_r1309674635
##########
python/pyspark/sql/functions.py:
##########
@@ -723,27 +750,67 @@ def desc(col: "ColumnOrName") -> Column:
Parameters
----------
col : :class:`~pyspark.sql.Column` or str
- target column to sort by in the descending order.
+ Target column to sort by in the descending order.
Returns
-------
:class:`~pyspark.sql.Column`
- the column specifying the order.
+ The column specifying the sort order.
Examples
--------
- Sort by the column 'id' in the descending order.
+ Example 1: Sort DataFrame by 'id' column in descending order.
- >>> spark.range(5).orderBy(desc("id")).show()
- +---+
- | id|
- +---+
- | 4|
- | 3|
- | 2|
- | 1|
- | 0|
- +---+
+ >>> from pyspark.sql.functions import desc
+ >>> df = spark.createDataFrame([(4, 'B'), (3, 'A'), (2, 'C')], ['id',
'value'])
+ >>> df.sort(desc("id")).show()
+ +---+-----+
+ | id|value|
+ +---+-----+
+ | 4| B|
+ | 3| A|
+ | 2| C|
+ +---+-----+
+
+ Example 2: Use `desc` in `orderBy` function to sort the DataFrame.
+
+ >>> from pyspark.sql.functions import desc
+ >>> df = spark.createDataFrame([(4, 'B'), (3, 'A'), (2, 'C')], ['id',
'value'])
+ >>> df.orderBy(desc("value")).show()
+ +---+-----+
+ | id|value|
+ +---+-----+
+ | 2| C|
+ | 4| B|
+ | 3| A|
+ +---+-----+
+
+ Example 3: Combine `asc` with `desc` to sort by multiple columns.
+
+ >>> from pyspark.sql.functions import asc, desc
Review Comment:
On second thought, I will try to change all the imports in functions.py in
one batch.
So no need to make a follow up :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]