Github user gatorsmile commented on the issue: https://github.com/apache/spark/pull/16739 Let me rewrite the test cases in Scala. ```Scala val df = spark.range(0, 10000, 1, 5) assert(df.rdd.getNumPartitions == 5) assert(df.coalesce(3).rdd.getNumPartitions == 3) assert(df.coalesce(6).rdd.getNumPartitions == 5) val df1 = df.coalesce(3) assert(df1.rdd.getNumPartitions == 3) assert(df1.coalesce(6).rdd.getNumPartitions == 5) assert(df1.coalesce(4).rdd.getNumPartitions == 4) assert(df1.coalesce(2).rdd.getNumPartitions == 2) val df2 = df.repartition(10) assert(df2.rdd.getNumPartitions == 10) assert(df2.coalesce(13).rdd.getNumPartitions == 5) assert(df2.coalesce(7).rdd.getNumPartitions == 5) assert(df2.coalesce(3).rdd.getNumPartitions == 3) ``` The question is why the second one is `5` instead of `10`. If we do the explain, we got the following plan ``` == Parsed Logical Plan == Repartition 13, false +- Repartition 10, true +- Range (0, 10000, step=1, splits=Some(5)) == Analyzed Logical Plan == id: bigint Repartition 13, false +- Repartition 10, true +- Range (0, 10000, step=1, splits=Some(5)) == Optimized Logical Plan == Repartition 13, false +- Range (0, 10000, step=1, splits=Some(5)) == Physical Plan == Coalesce 13 +- *Range (0, 10000, step=1, splits=Some(5)) ``` Ok... `Repartition 10, true` is removed by our Optimizer rule `CollapseRepartition`. It is a bug, I think. Your question is valid. Let me fix it.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org