Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21109#discussion_r188264496
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
 ---
    @@ -131,13 +134,101 @@ object ExtractEquiJoinKeys extends Logging with 
PredicateHelper {
     
           if (joinKeys.nonEmpty) {
             val (leftKeys, rightKeys) = joinKeys.unzip
    -        logDebug(s"leftKeys:$leftKeys | rightKeys:$rightKeys")
    -        Some((joinType, leftKeys, rightKeys, 
otherPredicates.reduceOption(And), left, right))
    +
    +        // Find any simple range expressions between two columns
    +        // (and involving only those two columns)
    +        // of the two tables being joined,
    +        // which are not used in the equijoin expressions,
    +        // and which can be used for secondary sort optimizations.
    +        val rangePreds: mutable.Set[Expression] = mutable.Set.empty
    +        var rangeConditions: Seq[BinaryComparison] =
    +          if (SQLConf.get.useSmjInnerRangeOptimization) { // && 
SQLConf.get.wholeStageEnabled) {
    +            otherPredicates.flatMap {
    +              case p@LessThan(l, r) => isValidRangeCondition(l, r, left, 
right, joinKeys) match {
    +                case "asis" => rangePreds.add(p); Some(LessThan(l, r))
    +                case "vs" => rangePreds.add(p); Some(GreaterThan(r, l))
    +                case _ => None
    +              }
    +              case p@LessThanOrEqual(l, r) =>
    +                isValidRangeCondition(l, r, left, right, joinKeys) match {
    +                  case "asis" => rangePreds.add(p); 
Some(LessThanOrEqual(l, r))
    +                  case "vs" => rangePreds.add(p); 
Some(GreaterThanOrEqual(r, l))
    +                  case _ => None
    +                }
    +              case p@GreaterThan(l, r) => isValidRangeCondition(l, r, 
left, right, joinKeys) match {
    +                case "asis" => rangePreds.add(p); Some(GreaterThan(l, r))
    +                case "vs" => rangePreds.add(p); Some(LessThan(r, l))
    +                case _ => None
    +              }
    +              case p@GreaterThanOrEqual(l, r) =>
    +                isValidRangeCondition(l, r, left, right, joinKeys) match {
    +                  case "asis" => rangePreds.add(p); 
Some(GreaterThanOrEqual(l, r))
    +                  case "vs" => rangePreds.add(p); Some(LessThanOrEqual(r, 
l))
    +                  case _ => None
    +                }
    +              case _ => None
    +            }
    +          }
    --- End diff --
    
    nit: `} else {`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to