c21 commented on a change in pull request #35574:
URL: https://github.com/apache/spark/pull/35574#discussion_r812470410
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala
##########
@@ -56,7 +57,23 @@ case class EnsureRequirements(
// Ensure that the operator's children satisfy their output distribution
requirements.
var children = originalChildren.zip(requiredChildDistributions).map {
case (child, distribution) if
child.outputPartitioning.satisfies(distribution) =>
- child
+ (child.outputPartitioning, distribution) match {
+ case (p: HashPartitioning, d: ClusteredDistribution) =>
+ if
(conf.getConf(SQLConf.REQUIRE_ALL_CLUSTER_KEYS_FOR_SOLE_PARTITION) &&
+ requiredChildDistributions.size == 1 &&
!p.isPartitionedOnFullKeys(d)) {
+ // Add an extra shuffle for `ClusteredDistribution` even though
its child
Review comment:
> Happy to learn what an alternative implementation for such a heuristic
would look like.
Alternatively I think this can be done as well, in a separate physical plan
rule post `EnsureRequirements`, e.g. below is a sketch of rule:
```scala
object AddShuffleForBooleanWindow extends Rule[SparkPlan] {
def apply(plan: SparkPlan): SparkPlan = {
plan.transformDown {
case w: WindowExecBase
if w.partitionSpec.exists(_.dataType.isInstanceOf[BooleanType]) =>
val distribution = w.requiredChildDistribution.head
val clustering =
distribution.asInstanceOf[ClusteredDistribution].clustering
w.child.outputPartitioning match {
case HashPartitioning(expressions, _)
if isPartitionOnFullKeys(expressions, clustering) => w
case p =>
val newPartitioning =
distribution.createPartitioning(p.numPartitions)
w.withNewChildren(w.child match {
case ShuffleExchangeExec(_, c, so) =>
Seq(ShuffleExchangeExec(newPartitioning, c, so))
case _ => Seq(ShuffleExchangeExec(newPartitioning, w.child))
})
}
case other => other
}
}
private def isPartitionOnFullKeys(
expressions: Seq[Expression], clustering: Seq[Expression]): Boolean = {
expressions.length == clustering.length &&
expressions.zip(clustering).forall {
case (l, r) => l.semanticEquals(r)
}
}
```
--
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]