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

    https://github.com/apache/spark/pull/19783#discussion_r153977529
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/EstimationUtils.scala
 ---
    @@ -114,4 +114,197 @@ object EstimationUtils {
         }
       }
     
    +  /**
    +   * Returns the number of the first bin into which a column values falls 
for a specified
    +   * numeric equi-height histogram.
    +   *
    +   * @param value a literal value of a column
    +   * @param histogram a numeric equi-height histogram
    +   * @return the number of the first bin into which a column values falls.
    +   */
    +
    +  def findFirstBinForValue(value: Double, histogram: Histogram): Int = {
    +    var binId = 0
    +    histogram.bins.foreach { bin =>
    +      if (value > bin.hi) binId += 1
    +    }
    +    binId
    +  }
    +
    +  /**
    +   * Returns the number of the last bin into which a column values falls 
for a specified
    +   * numeric equi-height histogram.
    +   *
    +   * @param value a literal value of a column
    +   * @param histogram a numeric equi-height histogram
    +   * @return the number of the last bin into which a column values falls.
    +   */
    +
    +  def findLastBinForValue(value: Double, histogram: Histogram): Int = {
    +    var binId = 0
    +    for (i <- 0 until histogram.bins.length) {
    +      if (value > histogram.bins(i).hi) {
    +        // increment binId to point to next bin
    +        binId += 1
    +      }
    +      if ((value == histogram.bins(i).hi) && (i < histogram.bins.length - 
1)) {
    +        if (value == histogram.bins(i + 1).lo) {
    +          // increment binId since the value appears into this bin and 
next bin
    --- End diff --
    
    appears in both this bin and the next bin


---

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

Reply via email to