Kimahriman commented on code in PR #706:
URL: https://github.com/apache/incubator-sedona/pull/706#discussion_r1013188064


##########
sql/src/main/scala/org/apache/spark/sql/sedona_sql/strategy/join/JoinQueryDetector.scala:
##########
@@ -164,9 +164,9 @@ class JoinQueryDetector(sparkSession: SparkSession) extends 
Strategy {
     val relationship = s"ST_$spatialPredicate"
 
     matchExpressionsToPlans(a, b, left, right) match {
-      case Some((planA, planB, _)) =>
+      case Some((planA, planB, swappedLeftAndRight)) =>
         logInfo(s"Planning spatial join for $relationship relationship")
-        RangeJoinExec(planLater(planA), planLater(planB), a, b, 
spatialPredicate, extraCondition) :: Nil
+        RangeJoinExec(planLater(planA), planLater(planB), a, b, 
swappedLeftAndRight, spatialPredicate, extraCondition) :: Nil

Review Comment:
   I'm trying to wrap my head around this a little bit. By inverting the 
spatial predicate do you mean like rewritting it? As in `ST_Contains(a, b)` -> 
`ST_Within(b, a)` or something like that?
   
   What would happen if you just swapped the left and right shapes if needed? 
Like
   ```scala
       matchExpressionsToPlans(a, b, left, right) match {
         case Some((_, _, swapped)) =>
           logInfo(s"Planning spatial join for $relationship relationship")
           if (swapped) {
             RangeJoinExec(planLater(left), planLater(right), b, a, 
spatialPredicate, extraCondition) :: Nil
           } else {
             RangeJoinExec(planLater(left), planLater(right), a, b, 
spatialPredicate, extraCondition) :: Nil
           }
         case None =>
           logInfo(
             s"Spatial join for $relationship with arguments not aligned " +
               "with join relations is not supported")
           Nil
       }
   ```
   
   I'm trying to think of why that wouldn't work



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

Reply via email to