dongjoon-hyun commented on code in PR #60785:
URL: https://github.com/apache/spark/pull/60785#discussion_r4660502350
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala:
##########
@@ -191,13 +191,37 @@ object ExtractEquiJoinKeys extends Logging with
PredicateHelper {
(JoinType, Seq[Expression], Seq[Expression],
Option[Expression], Option[Expression], LogicalPlan, LogicalPlan,
JoinHint)
- def unapply(join: Join): Option[ReturnType] = join match {
+ def unapply(join: Join): Option[ReturnType] = extract(join, allEqualities =
false)
+
+ /**
+ * Returns the keys of `join`. If `allEqualities` is false, a conjunct that
may not be evaluated
+ * ahead of the rest of the condition is not a key (see below), otherwise
every equality
+ * between the two sides is.
+ */
+ private[planning] def extract(
+ join: Join,
+ allEqualities: Boolean): Option[ReturnType] = join match {
case Join(left, right, joinType, condition, hint) =>
logDebug(s"Considering join on: $condition")
// Find equi-join predicates that can be evaluated before the join, and
thus can be used
- // as join keys.
+ // as join keys. A join computes its keys on every row of its inputs,
ahead of the rest of
+ // its condition, so a conjunct that may not be evaluated ahead of the
others (see
+ // `splitMovable`), e.g. one that can fail written after a throwable
one, is not a key. It
+ // stays in the other condition, in its written order. The first
conjunct is evaluated
+ // first on every pair anyway, so it may be a key unless it is
non-deterministic, also when
+ // it is throwable. The columns of the inputs that can fail
(`failableOutput`) do not
+ // count: a key over such a column reads the value that the projection
below computes,
+ // while a filter pushed below the projection evaluates its expression
again. This also
+ // keeps the keys the same when the inputs change, e.g. when AQE
replaces them with query
+ // stages.
val predicates = condition.map(splitConjunctivePredicates).getOrElse(Nil)
- val joinKeys = predicates.flatMap {
+ val notMovable = predicates match {
+ case _ if allEqualities => Nil
+ case first +: rest if first.deterministic =>
Review Comment:
Thank you. Yes, `PushPredicateThroughJoin` puts the conjuncts that may move
first, so a throwable equality stays first only when nothing after it may move,
e.g. `l.x = coalesce(r.w, raise_error('m'))` alone or followed only by
`CAST(l.s AS INT) = r.z`. That is the case where it matters, though: the join
has no other key there, and with it the join is a hash join on `x`, as on
`master`, instead of a nested loop join. With your example, the join is a hash
join on `w2`, and the throwable equality is in its other condition. So I kept
it, and the comment now says so. I also corrected the PR description, whose
table listed a case like yours as unchanged.
--
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]