@SuppressWarnings("unchecked")
    private RexNode reduceCall(RexLiteral literal, SqlKind kind, Number max, Number min) {
      // Stats were available, try to reduce
      if (max != null && min != null) {
        BigDecimal maxVal = new BigDecimal(max.floatValue());
        BigDecimal minVal = new BigDecimal(min.floatValue());
        RexLiteral maxLiteral = rexBuilder.makeExactLiteral(maxVal, literal.getType());
        RexLiteral minLiteral = rexBuilder.makeExactLiteral(minVal, literal.getType());

        // Equals
        if (kind == SqlKind.EQUALS) {
          if (minLiteral.getValue().compareTo(literal.getValue()) > 0 ||
                  maxLiteral.getValue().compareTo(literal.getValue()) < 0) {
            return rexBuilder.makeLiteral(false);
          }
        }

        // Greater than (or equal), and less than (or equal)
        if (kind == SqlKind.GREATER_THAN) {
          if (minLiteral.getValue().compareTo(literal.getValue()) > 0) {
            return rexBuilder.makeLiteral(true);
          } else if (maxLiteral.getValue().compareTo(literal.getValue()) <= 0) {
            return rexBuilder.makeLiteral(false);
          }
        } else if (kind == SqlKind.GREATER_THAN_OR_EQUAL) {
          if (minLiteral.getValue().compareTo(literal.getValue()) >= 0) {
            return rexBuilder.makeLiteral(true);
          } else if (maxLiteral.getValue().compareTo(literal.getValue()) < 0) {
            return rexBuilder.makeLiteral(false);
          }
        } else if (kind == SqlKind.LESS_THAN) {
          if (minLiteral.getValue().compareTo(literal.getValue()) >= 0) {
            return rexBuilder.makeLiteral(false);
          } else if (maxLiteral.getValue().compareTo(literal.getValue()) < 0) {
            return rexBuilder.makeLiteral(true);
          }
        } else if (kind == SqlKind.LESS_THAN_OR_EQUAL) {
          if (minLiteral.getValue().compareTo(literal.getValue()) > 0) {
            return rexBuilder.makeLiteral(false);
          } else if (maxLiteral.getValue().compareTo(literal.getValue()) <= 0) {
            return rexBuilder.makeLiteral(true);
          }
        }
      }
      return null;
    }
Replaces expressions with their reductions. Note that we only have to
look for RexCall, since nothing else is reducible in the first place.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveReduceExpressionsWithStatsRule.java