agrawaldevesh commented on a change in pull request #29104: URL: https://github.com/apache/spark/pull/29104#discussion_r458275315
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala ########## @@ -388,3 +390,35 @@ object PhysicalWindow { case _ => None } } + +object ExtractSingleColumnNullAwareAntiJoin extends JoinSelectionHelper with PredicateHelper { + + // SingleColumn NullAwareAntiJoin + // streamedSideKeys, buildSideKeys + // currently these two return Seq[Expression] should have only one element + private type ReturnType = (Seq[Expression], Seq[Expression]) + + /** + * See. [SPARK-32290] + * LeftAnti(condition: Or(EqualTo(a=b), IsNull(EqualTo(a=b))) + * will almost certainly be planned as a Broadcast Nested Loop join, + * which is very time consuming because it's an O(M*N) calculation. + * But if it's a single column case, and buildSide data is small enough, + * O(M*N) calculation could be optimized into O(M) using hash lookup instead of loop lookup. + */ + def unapply(join: Join): Option[ReturnType] = join match { + case Join(left, right, LeftAnti, + Some(Or(EqualTo(leftAttr: AttributeReference, rightAttr: AttributeReference), + IsNull(EqualTo(tmpLeft: AttributeReference, tmpRight: AttributeReference)))), _) + if SQLConf.get.nullAwareAntiJoinOptimizeEnabled && + leftAttr.semanticEquals(tmpLeft) && rightAttr.semanticEquals(tmpRight) => + if (canEvaluate(leftAttr, left) && canEvaluate(rightAttr, right)) { + Some(Seq(leftAttr), Seq(rightAttr)) + } else if (canEvaluate(leftAttr, right) && canEvaluate(rightAttr, left)) { Review comment: Thanks for adding this. Is this covered in the positive/negative test case below ? ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org