private RelNode rewriteFilter(Filter matchNode) {
    try {
      final Filter filter = matchNode;
      final RelNode input = filter.getInput();

      final RexNode originalCond = filter.getCondition();
      final RexSortPredicatesShuttle sortPredicatesShuttle = new RexSortPredicatesShuttle(
          input, filter.getCluster().getMetadataQuery());
      final RexNode newCond = originalCond.accept(sortPredicatesShuttle);
      if (!sortPredicatesShuttle.modified) {
        // We are done, bail out
        return matchNode;
      }

      // We register the new filter so we do not fire the rule on it again
      final Filter newFilter = filter.copy(filter.getTraitSet(), input, newCond);
      return newFilter;
    }
    catch (Exception e) {
      if (noColsMissingStats.get() > 0) {
        LOG.warn("Missing column stats (see previous messages), skipping sort predicates in filter expressions in CBO");
        noColsMissingStats.set(0);
      } else {
        throw e;
      }
    }
    return matchNode;
  }
Sorts conditions in a filter predicate to accelerate query processing
based on selectivity and compute cost. Currently it is not applied recursively,
i.e., it is only applied to top predicates in the condition.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveFilterSortPredicates.java