LukaZdravic commented on code in PR #60403:
URL: https://github.com/apache/spark/pull/60403#discussion_r4586098249
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2315,6 +2321,32 @@ object InferFiltersFromConstraints extends
Rule[LogicalPlan]
case _ => join
}
+
+ // A right row that fails the ON condition is never the match of any left
row, so a filter
+ // that follows from the left constraints and the ON condition can drop it
before the join.
+ // An inner join also drops the left rows without a match, so its left
side gets one too.
+ case j: AsOfJoin if conf.inferFiltersAcrossAsOfJoinEnabled =>
+ val allConstraints = getAllConstraints(j.left, j.right, j.condition)
+ val newLeft = j.joinType match {
+ case Inner => inferAsOfInputFilter(j.left, allConstraints)
+ case LeftOuter => j.left
+ case other =>
+ throw SparkException.internalError(s"Unexpected as-of join type:
$other")
+ }
+ // The join reads the right input lazily and reads one row past each key
group. A right
+ // filter changes which rows it reads, so a right ON key or a right
input expression that
+ // can fail could fail on a row the join did not read before.
+ val rightKeys =
+ j.condition.toSeq.flatMap(AsOfJoin.extractEquiJoinKeys(_, j.left,
j.right)._2)
+ val newRight = if (rightKeys.forall(cannotFail) &&
cannotFailAnywhere(j.right)) {
Review Comment:
Confirmed with a run (2 scans and no reused exchange, against 1 and 1). The
comment and the PR description now state the inner self-join cost, the
alternative and why the left filter stays.
--
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]