private long evaluateBetweenExpr(Statistics stats, ExprNodeDesc pred, long currNumRows, AnnotateStatsProcCtx aspCtx,
        List<String> neededCols, Operator<?> op) throws SemanticException {
      final ExprNodeGenericFuncDesc fd = (ExprNodeGenericFuncDesc) pred;
      final boolean invert = Boolean.TRUE.equals(
          ((ExprNodeConstantDesc) fd.getChildren().get(0)).getValue()); // boolean invert (not)
      final ExprNodeDesc comparisonExpression = fd.getChildren().get(1); // expression
      final ExprNodeDesc leftExpression = fd.getChildren().get(2); // left expression
      final ExprNodeDesc rightExpression = fd.getChildren().get(3); // right expression

      // Short circuit and return the current number of rows if this is a
      // synthetic predicate with dynamic values
      if (leftExpression instanceof ExprNodeDynamicValueDesc) {
        return currNumRows;
      }

      final String leftValueString = leftExpression instanceof ExprNodeConstantDesc
          ? ((ExprNodeConstantDesc) leftExpression).getValue().toString() : leftExpression.getExprString();
      final String rightValueString = rightExpression instanceof ExprNodeConstantDesc
          ? ((ExprNodeConstantDesc) rightExpression).getValue().toString() : rightExpression.getExprString();

      try {
        if (comparisonExpression instanceof ExprNodeColumnDesc) {
          final ExprNodeColumnDesc columnDesc = (ExprNodeColumnDesc) comparisonExpression;
          ColStatistics cs = stats.getColumnStatisticsFromColName(columnDesc.getColumn());
          if (FilterSelectivityEstimator.isHistogramAvailable(cs)) {
            final KllFloatsSketch kll = KllFloatsSketch.heapify(Memory.wrap(cs.getHistogram()));
            final String colTypeLowerCase = columnDesc.getTypeString().toLowerCase();
            final float leftValue = extractFloatFromLiteralValue(colTypeLowerCase, leftValueString);
            final float rightValue = extractFloatFromLiteralValue(colTypeLowerCase, rightValueString);
            if (invert) {
              // column < leftValue OR column > rightValue
              if (rightValue < leftValue) {
                return kll.getN();
              }
              return Math.round(kll.getN() * (lessThanSelectivity(kll, leftValue) + greaterThanSelectivity(kll, rightValue)));
            }
            // if they are equal we can't handle it here, it becomes an equality predicate
            if (Float.compare(leftValue, rightValue) != 0) {
              return Math.round(kll.getN() * FilterSelectivityEstimator.betweenSelectivity(kll, leftValue, rightValue));
            }
          }
        }
      } catch(RuntimeException e) {
        LOG.debug("Selectivity computation using histogram failed to parse the left ({}) or the right ({}) "
            + "boundary value, using the generic computation strategy", leftValueString, rightValueString, e);
      }

      ExprNodeDesc newExpression = rewriteBetweenToIn(comparisonExpression, leftExpression, rightExpression, invert);

      return evaluateExpression(stats, newExpression, aspCtx, neededCols, op, currNumRows);
    }
removes all values which are outside of the scope of the column
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java