beliefer commented on code in PR #43144:
URL: https://github.com/apache/spark/pull/43144#discussion_r1349455263


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -1241,6 +1242,23 @@ object OptimizeRepartition extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Remove window partition if partition expressions are foldable
+ */
+object EliminateWindowPartitions extends Rule[LogicalPlan] {
+  override def apply(plan: LogicalPlan): LogicalPlan = 
plan.transformWithPruning(
+    _.containsPattern(WINDOW), ruleId) {
+      case w @ Window(we, ps, _, _) if ps.exists(_.foldable) =>
+        val newWe = we.map {
+          _.transform {
+            case wsc @ WindowSpecDefinition(_ps, _, _) if 
_ps.exists(_.foldable) =>
+              wsc.copy(partitionSpec = _ps.filter(!_.foldable))
+          }.asInstanceOf[NamedExpression]
+        }
+        w.copy(windowExpressions = newWe, partitionSpec = 
ps.filter(!_.foldable))

Review Comment:
   I haven't actually built it, just for reference. You should ensure that it 
is correct.
   
   Could we make the variable name more readable? e.g. `we` => `windowExprs` or 
`windowExpressions` and others.



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