ulysses-you commented on code in PR #59535:
URL: https://github.com/apache/spark/pull/59535#discussion_r4335370900


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/basicPhysicalOperators.scala:
##########
@@ -1040,6 +1036,42 @@ case class UnionExec(children: Seq[SparkPlan]) extends 
SparkPlan with CodegenSup
     }
   }
 
+  /**
+   * Whether the legs' markers let their keys be merged. A marked leg may hold 
rows of a key it
+   * does not declare, and `KeyGroupedPartitioner` routes those into the 
partition of some declared
+   * key. Two conditions keep every key's rows in one group, which is what a 
clustering reads:
+   *
+   *   - a marked leg declares every key the other legs declare, so its rows 
of such a key do not
+   *     land in a partition the merge names for another key;
+   *   - marked legs declare the same keys in the same order, and when more 
than one is marked,
+   *     each still routes by the hash. A routed leg is grouped, so its keys 
are unique and the
+   *     list length is the modulus the hash is taken over: the position in 
that list is the name a
+   *     key no leg declares reaches, and equal lists agree on both. A leg 
whose routing is lost
+   *     names such a key by an earlier layout's order, which its list does 
not show. One marked
+   *     leg needs no agreement, since its undeclared rows reach one group 
either way.
+   *
+   * The merged layout cannot claim that a partition holds only the key it 
names, which
+   * [[KeyedPartitioning.concat]] records.
+   */
+  private def canMergeMarkedKeys(kps: Seq[KeyedPartitioning]): Boolean = {
+    val marked = kps.filter(_.mayContainUnknownPartitionKeys)
+    if (marked.isEmpty) {
+      true
+    } else {
+      val declared = marked.head.partitionKeys
+      marked.tail.forall(_.partitionKeys == declared) &&
+        (marked.size == 1 || marked.forall(_.unknownKeysRouted)) && {

Review Comment:
   Addressed



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