Github user wzhfy commented on a diff in the pull request: https://github.com/apache/spark/pull/19783#discussion_r153972336 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/FilterEstimation.scala --- @@ -332,8 +332,45 @@ case class FilterEstimation(plan: Filter) extends Logging { colStatsMap.update(attr, newStats) } - Some(1.0 / BigDecimal(ndv)) - } else { + // We compute filter selectivity using Histogram information + attr.dataType match { + case StringType | BinaryType => + Some(1.0 / BigDecimal(ndv)) + + case _ => + // returns 1/ndv if there is no histogram + if (colStat.histogram.isEmpty) return Some(1.0 / BigDecimal(ndv)) + + // We traverse histogram bins to locate the literal value + val hgmBins = colStat.histogram.get.bins + val datum = EstimationUtils.toDecimal(literal.value, literal.dataType).toDouble + // find the interval where this datum locates --- End diff -- we can remove this comment, it's explained above
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org