cloud-fan commented on code in PR #42317:
URL: https://github.com/apache/spark/pull/42317#discussion_r1360440880
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -143,41 +143,62 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with
PredicateHelper with J
referencedExprs.map(_.references).foldLeft(AttributeSet.empty)(_
++ _),
hasHitFilter,
hasHitSelectiveFilter,
- currentPlan)
+ currentPlan,
+ targetCreationSideExpr)
} else {
None
}
case Project(_, child) =>
assert(predicateReference.isEmpty && !hasHitSelectiveFilter)
- extract(child, predicateReference, hasHitFilter,
hasHitSelectiveFilter, currentPlan)
+ extract(child, predicateReference, hasHitFilter,
hasHitSelectiveFilter, currentPlan,
+ targetCreationSideExpr)
case Filter(condition, child) if isSimpleExpression(condition) =>
extract(
child,
predicateReference ++ condition.references,
hasHitFilter = true,
hasHitSelectiveFilter = hasHitSelectiveFilter ||
isLikelySelective(condition),
- currentPlan)
- case ExtractEquiJoinKeys(_, _, _, _, _, left, right, _) =>
+ currentPlan,
+ targetCreationSideExpr)
+ case ExtractEquiJoinKeys(_, lkeys, rkeys, _, _, left, right, _) =>
// Runtime filters use one side of the [[Join]] to build a set of join
key values and prune
// the other side of the [[Join]]. It's also OK to use a superset of
the join key values
// (ignore null values) to do the pruning.
if (left.output.exists(_.semanticEquals(filterCreationSideKey))) {
extract(left, AttributeSet.empty,
- hasHitFilter = false, hasHitSelectiveFilter = false, currentPlan =
left)
+ hasHitFilter = false, hasHitSelectiveFilter = false, currentPlan =
left,
+ targetCreationSideExpr = targetCreationSideExpr).orElse {
+ // We can also extract from the right side if the join keys are
transitive.
+
lkeys.zip(rkeys).find(_._1.semanticEquals(targetCreationSideExpr)).map(_._2)
+ .flatMap { passedFilterCreationSideExp =>
+ extract(right, AttributeSet.empty,
+ hasHitFilter = false, hasHitSelectiveFilter = false,
currentPlan = right,
Review Comment:
let's also add tests to cover this case.
--
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]