cloud-fan commented on a change in pull request #34785:
URL: https://github.com/apache/spark/pull/34785#discussion_r776570281



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DistributionAndOrderingUtils.scala
##########
@@ -36,16 +36,27 @@ object DistributionAndOrderingUtils {
         case _: UnspecifiedDistribution => Array.empty[Expression]
       }
 
+      val (sortOrder, _) = distribution.partition(_.isInstanceOf[SortOrder])
+
       val queryWithDistribution = if (distribution.nonEmpty) {
-        val finalNumPartitions = if (numPartitions > 0) {
-          numPartitions
+        // Spark can optimize the partition when
+        // 1. numPartitions is not specified by the data source, and
+        // 2. sortOrder is specified. This is because the requested 
distribution needs to be
+        // guaranteed, which can only be achieved by using RangePartitioning, 
not HashPartitioning.

Review comment:
       Anyway, we need a DS v2 API to let the sink require "rough" hash 
partitioning. If we don't want to change the existing API, we need to add a new 
one for it.




-- 
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]

Reply via email to