You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/10/22 10:56:48 UTC

[GitHub] [spark] zhengruifeng commented on pull request #34367: [SPARK-37099][SQL] Impl a rank-based filter to optimize top-k computation

zhengruifeng commented 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.replaceWindowTop.enabled", "true")
   
   df1.withColumn("rank", row_number().over(Window.partitionBy("hash1").orderBy("value1"))).where(col("rank") <= 1).write.mode("overwrite").parquet("/tmp/tmp2")
   ```
   
   ![image](https://user-images.githubusercontent.com/7322292/138442467-05114fc2-46a3-48f3-aafe-3ce929d9cb24.png)
   
   existing plan took 33 sec, while the new plan with `RankLimit` took only 8 sec.
   
   ![image](https://user-images.githubusercontent.com/7322292/138442603-ca117469-9de4-4220-8b01-0b816fba7fa6.png)
   
   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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org