zhengruifeng edited a comment on pull request #34367:
URL: https://github.com/apache/spark/pull/34367#issuecomment-949516811
a simple example:
```
import org.apache.spark.sql.expressions.Window
val df1 = spark.range(0, 100000000, 1, 9).select(when('id < 90000000,
123).otherwise('id).as("key1"), 'id as "value1").withColumn("hash1",
abs(hash(col("key1"))).mod(1000))
df1.withColumn("rank",
row_number().over(Window.partitionBy("hash1").orderBy("value1"))).where(col("rank")
<= 1).write.mode("overwrite").parquet("/tmp/tmp1")
spark.conf.set("spark.sql.rankLimit.enabled", "true")
df1.withColumn("rank",
row_number().over(Window.partitionBy("hash1").orderBy("value1"))).where(col("rank")
<= 1).write.mode("overwrite").parquet("/tmp/tmp2")
```

existing plan took 33 sec, while the new plan with `RankLimit` took only 8
sec.

and the shuffle write was reduced from 544.9 MiB to 26.7 KiB
```
== Physical Plan ==
Execute InsertIntoHadoopFsRelationCommand (18)
+- AdaptiveSparkPlan (17)
+- == Final Plan ==
* Filter (11)
+- Window (10)
+- * Sort (9)
+- AQEShuffleRead (8)
+- ShuffleQueryStage (7)
+- Exchange (6)
+- RankLimit (5)
+- * Sort (4)
+- * Project (3)
+- * Project (2)
+- * Range (1)
```
--
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]