yadavay-amzn commented on code in PR #56101:
URL: https://github.com/apache/spark/pull/56101#discussion_r3677055776


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/NearestByJoin.scala:
##########
@@ -20,10 +20,17 @@ package org.apache.spark.sql.catalyst.plans.logical
 import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
 import org.apache.spark.sql.catalyst.plans.{Inner, JoinType, LeftOuter, 
NearestByDirection, NearestByJoinValidation}
 import org.apache.spark.sql.catalyst.trees.TreePattern._
+import org.apache.spark.sql.internal.SQLConf
 
 object NearestByJoin {
   /** @see [[NearestByJoinValidation.MaxNumResults]] */
   val MaxNumResults: Int = NearestByJoinValidation.MaxNumResults
+
+  /** Whether the right side of a NearestByJoin is eligible for broadcast 
execution. */
+  def canBroadcastRight(j: NearestByJoin, conf: SQLConf): Boolean =
+    conf.nearestByBroadcastEnabled &&
+      j.right.stats.sizeInBytes >= 0 &&

Review Comment:
   You're right, and thanks for the repro. I took option (a): 
`RewriteNearestByJoin` now gates only on the flag 
(`!nearestByBroadcastEnabled`) and reads no stats, so nothing touches `stats` 
in `FinishAnalysis` anymore. `NearestByJoinSelection` drops the size test and 
always plans the operator when the flag is on, so the two sites agree by 
construction and the DSv2/partitioned cases work. The contract is now what you 
described: for this internal, default-off flag, on means always use the 
operator (giving up the automatic large-right fallback). Added a flag-on DSv2 
test with `InMemoryTableCatalog` (your repro, which threw `INTERNAL_ERROR` 
before) and a partitioned-table test that now fires the operator.
   
   Separately on Finding 3 (non-blocking): the heap only offers when it isn't 
full or the candidate beats `peek()`, and the variable-length `.copy()` now 
runs only for rows that are actually kept, so evicted rows cost nothing. Same 
top-k output.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala:
##########
@@ -178,6 +178,21 @@ abstract class SparkStrategies extends 
QueryPlanner[SparkPlan] {
    *     Supports both equi-joins and non-equi-joins.
    *     Supports only inner like joins.
    */
+
+  object NearestByJoinSelection extends Strategy {

Review Comment:
   Done, moved `NearestByJoinSelection` below `JoinSelection` so the 
strategy-selection scaladoc attaches back to `JoinSelection`.



-- 
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]

Reply via email to