sigmod commented on a change in pull request #32060:
URL: https://github.com/apache/spark/pull/32060#discussion_r608486639



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
##########
@@ -80,28 +105,57 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
    * transformExpressionsDown or transformExpressionsUp should be used.
    *
    * @param rule the rule to be applied to every expression in this operator.
+   * @param cond  a Lambda expression to prune tree traversals. If 
`cond.apply` returns false
+   *              on an expression T, skips processing T and its subtree; 
otherwise, processes
+   *              T and its subtree recursively.
+   * @param ruleId is a unique Id for `rule` to prune unnecessary tree 
traversals. When it is
+   *        RuleId.UnknownId, no pruning happens. Otherwise, if `rule`(with id 
`ruleId`) has been
+   *        marked as in effective on an expression T, skips processing T and 
its subtree. Do not
+   *        pass it if the rule is not purely functional and reads a varying 
initial state for
+   *        different invocations.
    */
-  def transformExpressions(rule: PartialFunction[Expression, Expression]): 
this.type = {
-    transformExpressionsDown(rule)
+  def transformExpressions(rule: PartialFunction[Expression, Expression],
+    cond: TreePatternBits => Boolean = AlwaysProcess.fn,
+    ruleId: Int = RuleIdCollection.UnknownId): this.type = {

Review comment:
       Yes, that's definitely a better approach -- if I implement it from 
scratch, I'd do that way.
   However, I don't have a good idea to get existing code like "plan transform 
{...}" compile if change "rule: PartialFunction" to "rule: Rule".  If we change 
every call sites of transform, the PR might go too large.




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