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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DistributionAndOrderingUtils.scala
##########
@@ -32,21 +32,26 @@ object DistributionAndOrderingUtils {
     case write: RequiresDistributionAndOrdering =>
       val resolver = conf.resolver
 
+      val numPartitions = write.requiredNumPartitions()
       val distribution = write.requiredDistribution match {
-        case d: OrderedDistribution =>
-          d.ordering.map(e => toCatalyst(e, query, resolver))
-        case d: ClusteredDistribution =>
-          d.clustering.map(e => toCatalyst(e, query, resolver))
-        case _: UnspecifiedDistribution =>
-          Array.empty[Expression]
+        case d: OrderedDistribution => d.ordering.map(e => toCatalyst(e, 
query, resolver))
+        case d: ClusteredDistribution => d.clustering.map(e => toCatalyst(e, 
query, resolver))
+        case _: UnspecifiedDistribution => Array.empty[Expression]
       }
 
       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 if (numPartitions > 0) {
+        throw new AnalysisException("The number of partitions can't be 
specified with unspecified" +

Review comment:
       let's move it to `QueryCompilationErrors.scala`




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to