cloud-fan commented on code in PR #42317:
URL: https://github.com/apache/spark/pull/42317#discussion_r1354845923


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -121,14 +128,44 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
    */
   private def extractSelectiveFilterOverScan(
       plan: LogicalPlan,
-      filterCreationSideExp: Expression): Option[LogicalPlan] = {
-    @tailrec
+      filterCreationSideExp: Expression): Option[(Expression, LogicalPlan)] = {
+
+    /**
+     * Find the passed creation side expression.
+     *
+     * Note: If one side of the join condition contains the current creation 
side expression,
+     * the expression on the other side of the join condition can be used as
+     * the passed creation side.
+     */
+    def findPassedFilterCreationSideExp(
+        joinKeys: Seq[Expression],
+        otherJoinKeys: Seq[Expression],
+        filterCreationSideExp: Expression): Option[Expression] = {
+      joinKeys.zipWithIndex.find { case (key, _) =>
+        filterCreationSideExp.semanticEquals(key)
+      }.map { case (_, idx) =>
+        otherJoinKeys(idx)
+      }
+    }
+
+    /**
+     * Extracts a sub-plan which is a simple filter over scan from the input 
plan iteratively
+     * by the way show below:
+     * - Extracts a sub-plan from a plan without join nodes.
+     * - Extracts a sub-plan from left or right child of join nodes.
+     *
+     * Note: There are two situations if extracts a sub-plan from any child of 
join nodes.
+     * If we can extract a sub-plan from one child of join node, using it 
directly.
+     * Otherwise, we extract a sub-plan from another child of join node if
+     * we can find out the passed creation side expression.
+     */
     def extract(
         p: LogicalPlan,
         predicateReference: AttributeSet,
         hasHitFilter: Boolean,
         hasHitSelectiveFilter: Boolean,
-        currentPlan: LogicalPlan): Option[LogicalPlan] = p match {
+        currentPlan: LogicalPlan,
+        currentFilterCreationSideExp: Expression): Option[(Expression, 
LogicalPlan)] = p match {

Review Comment:
   `current` is a bit weird here. How about `targetCreationSideExpr`?



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