ammarchalifah commented on code in PR #59599:
URL: https://github.com/apache/spark/pull/59599#discussion_r4377523324


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -347,8 +352,8 @@ case class EnsureRequirements(
         // Sort 'commonPartitionValues' and use this mechanism to ensure 
BatchScan's
         // output partitions are ordered
         val sorted = partitionValues.sorted(partitionOrdering)
-        populateCommonPartitionInfo(plan, sorted.map((_, 1)),
-          None, None, applyPartialClustering = false, replicatePartitions = 
false)
+        populateSpjParams(plan, Some(sorted.map((_, 1))), None,

Review Comment:
   Addressed



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/KeyGroupedPartitionedScan.scala:
##########
@@ -18,13 +18,51 @@
 package org.apache.spark.sql.execution
 
 import org.apache.spark.sql.catalyst.InternalRow
-import org.apache.spark.sql.catalyst.expressions.RowOrdering
+import org.apache.spark.sql.catalyst.expressions.{Expression, RowOrdering}
 import org.apache.spark.sql.catalyst.plans.physical.{KeyGroupedPartitioning, 
KeyGroupedShuffleSpec}
 import org.apache.spark.sql.catalyst.util.InternalRowComparableWrapper
 import org.apache.spark.sql.execution.joins.StoragePartitionJoinParams
 
 /** Base trait for a data source scan capable of producing a key-grouped 
output. */
 trait KeyGroupedPartitionedScan[T] {
+  /**
+   * Return join-key positions for `outputPartitioning`. 
[[getInputPartitionGrouping]] always
+   * uses `spjParams.joinKeyPositions`. Skip output projection for a 
leading-prefix subset of
+   * partition keys when common-partition metadata remains at full width; 
projecting output
+   * misaligns nested siblings in a
+   * [[org.apache.spark.sql.catalyst.plans.physical.PartitioningCollection]].
+   */
+  private def joinKeyPositionsForOutput(
+      spjParams: StoragePartitionJoinParams,
+      baseExpressions: Seq[Expression]): Option[Seq[Int]] = {
+    spjParams.joinKeyPositions match {
+      case Some(pos) if pos.length < baseExpressions.length &&
+          pos == (0 until pos.length).toSeq &&
+          spjParams.commonPartitionValues.exists(
+            _.exists(_._1.numFields == baseExpressions.length)) =>
+        None
+      case other => spjParams.joinKeyPositions
+    }
+  }
+
+  private def projectCommonPartitionValuesIfNeeded(
+      commonPartValues: Seq[(InternalRow, Int)],
+      baseExpressions: Seq[Expression],
+      joinKeyPositions: Option[Seq[Int]]): Seq[(InternalRow, Int)] = {
+    joinKeyPositions match {
+      case Some(projectionPositions) =>
+        // Project only when common values match full partition-key width.
+        commonPartValues.map { case (partValue, numSplits) =>
+          if (partValue.numFields == baseExpressions.length) {

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