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/03/02 05:29:57 UTC

[GitHub] [spark] HeartSaVioR commented on a change in pull request #31355: [SPARK-34255][SQL] Support partitioning with static number on required distribution and ordering on V2 write

HeartSaVioR commented on a change in pull request #31355:
URL: https://github.com/apache/spark/pull/31355#discussion_r585270435



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DistributionAndOrderingUtils.scala
##########
@@ -32,23 +32,34 @@ object DistributionAndOrderingUtils {
     case write: RequiresDistributionAndOrdering =>
       val resolver = conf.resolver
 
-      val distribution = write.requiredDistribution match {
+      val numParts = write.requiredNumPartitions()
+      val (distribution, numPartitions) = write.requiredDistribution match {
         case d: OrderedDistribution =>
-          d.ordering.map(e => toCatalyst(e, query, resolver))
+          val dist = d.ordering.map(e => toCatalyst(e, query, resolver))
+          (dist, numParts)
         case d: ClusteredDistribution =>
-          d.clustering.map(e => toCatalyst(e, query, resolver))
+          val dist = d.clustering.map(e => toCatalyst(e, query, resolver))
+          (dist, numParts)
         case _: UnspecifiedDistribution =>
-          Array.empty[Expression]
+          (Array.empty[Expression], numParts)
       }
 
       val queryWithDistribution = if (distribution.nonEmpty) {
-        val numShufflePartitions = conf.numShufflePartitions
+        val finalNumPartitions = if (numPartitions > 0) {
+          numPartitions
+        } else {
+          conf.numShufflePartitions
+        }
         // the conversion to catalyst expressions above produces SortOrder expressions
         // for OrderedDistribution and generic expressions for ClusteredDistribution
         // this allows RepartitionByExpression to pick either range or hash partitioning
-        RepartitionByExpression(distribution, query, numShufflePartitions)
+        RepartitionByExpression(distribution, query, finalNumPartitions)
       } else {
-        query
+        if (numPartitions > 0) {
+          Repartition(numPartitions, shuffle = true, query)

Review comment:
       @aokolnychyi kindly reminder.




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

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