spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wzhfy <...@git.apache.org>
Subject [GitHub] spark pull request #17148: [SPARK-17075][SQL][followup] fix filter estimatio...
Date Sat, 04 Mar 2017 06:14:45 GMT
Github user wzhfy commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17148#discussion_r104280853
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/FilterEstimation.scala
---
    @@ -414,53 +422,63 @@ case class FilterEstimation(plan: Filter, catalystConf: CatalystConf)
extends Lo
           literal: Literal,
           update: Boolean): Option[Double] = {
     
    -    var percent = 1.0
         val colStat = colStatsMap(attr)
    -    val statsRange =
    -      Range(colStat.min, colStat.max, attr.dataType).asInstanceOf[NumericRange]
    +    val statsRange = Range(colStat.min, colStat.max, attr.dataType).asInstanceOf[NumericRange]
    +    val max = BigDecimal(statsRange.max)
    +    val min = BigDecimal(statsRange.min)
    +    val ndv = BigDecimal(colStat.distinctCount)
     
         // determine the overlapping degree between predicate range and column's range
    -    val literalValueBD = BigDecimal(literal.value.toString)
    +    val numericLiteral = if (literal.dataType.isInstanceOf[BooleanType]) {
    +      if (literal.value.asInstanceOf[Boolean]) BigDecimal(1) else BigDecimal(0)
    +    } else {
    +      BigDecimal(literal.value.toString)
    +    }
         val (noOverlap: Boolean, completeOverlap: Boolean) = op match {
           case _: LessThan =>
    -        (literalValueBD <= statsRange.min, literalValueBD > statsRange.max)
    +        (numericLiteral <= min, numericLiteral > max)
           case _: LessThanOrEqual =>
    -        (literalValueBD < statsRange.min, literalValueBD >= statsRange.max)
    +        (numericLiteral < min, numericLiteral >= max)
           case _: GreaterThan =>
    -        (literalValueBD >= statsRange.max, literalValueBD < statsRange.min)
    +        (numericLiteral >= max, numericLiteral < min)
           case _: GreaterThanOrEqual =>
    -        (literalValueBD > statsRange.max, literalValueBD <= statsRange.min)
    +        (numericLiteral > max, numericLiteral <= min)
         }
     
    +    var percent = BigDecimal(1.0)
         if (noOverlap) {
           percent = 0.0
         } else if (completeOverlap) {
           percent = 1.0
         } else {
    -      // this is partial overlap case
    -      val literalDouble = literalValueBD.toDouble
    -      val maxDouble = BigDecimal(statsRange.max).toDouble
    -      val minDouble = BigDecimal(statsRange.min).toDouble
    -
    +      // This is the partial overlap case:
           // Without advanced statistics like histogram, we assume uniform data distribution.
           // We just prorate the adjusted range over the initial range to compute filter
selectivity.
    -      // For ease of computation, we convert all relevant numeric values to Double.
    +      assert(max > min)
    --- End diff --
    
    it's in the partial overlap case, if max == min, it must be either no overlap or complete
overlap for a binary expression. see here:
    ```
    val (noOverlap: Boolean, completeOverlap: Boolean) = op match {
          case _: LessThan =>
            (numericLiteral <= min, numericLiteral > max)
          case _: LessThanOrEqual =>
            (numericLiteral < min, numericLiteral >= max)
          case _: GreaterThan =>
            (numericLiteral >= max, numericLiteral < min)
          case _: GreaterThanOrEqual =>
            (numericLiteral > max, numericLiteral <= min)
        }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message