cloud-fan commented on a change in pull request #29104:
URL: https://github.com/apache/spark/pull/29104#discussion_r459010024



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastHashJoinExec.scala
##########
@@ -454,6 +478,28 @@ case class BroadcastHashJoinExec(
     val (matched, checkCondition, _) = getJoinCondition(ctx, input)
     val numOutput = metricTerm(ctx, "numOutputRows")
 
+    if (isNullAwareAntiJoin) {
+      require(leftKeys.length == 1, "leftKeys length should be 1")
+      require(rightKeys.length == 1, "rightKeys length should be 1")
+      require(joinType == LeftAnti, "joinType must be LeftAnti.")
+      require(buildSide == BuildRight, "buildSide must be BuildRight.")
+      require(SQLConf.get.nullAwareAntiJoinOptimizeEnabled,
+        "nullAwareAntiJoinOptimizeEnabled must be on for null aware anti join 
optimize.")
+      require(checkCondition == "", "null aware anti join optimize condition 
should be empty.")
+
+      if (broadcastRelation.value.inputEmpty) {
+        return s"""
+           |// singleColumn NAAJ inputEmpty(true) accept all
+           |$numOutput.add(1);
+           |${consume(ctx, input)}
+         """.stripMargin
+      } else if (broadcastRelation.value.anyNullKeyExists) {
+        return s"""
+           |// singleColumn NAAJ inputEmpty(false) anyNullKeyExists(true) 
reject all

Review comment:
       So there are only 3 special changes for NAAJ on the codegen path, and in 
total just 5 lines. If we can further unify the code for `uniqueKeyCodePath` 
and not unique, there will be only 2 special changes for NAAJ.
   
   The `doExecute` is fine as there is a big `if-else` at the beginning to 
diverge between NAAJ and normal anti join. I don't think it hurts readability 
too much.
   
   So I think it's better to reuse BHJ, as a new node has a large maintenance 
cost. The tradeoff is between the readability of BHJ and maintenance cost of a 
new node, but as I explained I think the readability of BHJ won't be hurt too 
much.
   
   @maryannxue @agrawaldevesh @maropu @viirya what do you think?




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to