cloud-fan commented on a change in pull request #34785:
URL: https://github.com/apache/spark/pull/34785#discussion_r776570070
##########
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:
This looks too strict. Do we have a reason to must keep the hash
partitioning? For file sources, we want to shuffle by partition columns to
reduce the number of files, but it's just a best effort as a rough hash
partitioning also works.
Do we have other special requirements for DS v2?
--
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]