@Override
    public SearchArgument build() {
      if (currentTree.size() != 1) {
        throw new IllegalArgumentException("Failed to end " +
            currentTree.size() + " operations.");
      }
      ExpressionTree optimized = optimize(root);
      ExpressionTree expanded = convertToCNF(new ExpressionTree(optimized));
      expanded = flatten(expanded);
      List<PredicateLeaf> finalLeaves = new ArrayList<>(leaves.size());
      compactLeaves(expanded, finalLeaves);
      return new SearchArgumentImpl(expanded, optimized, finalLeaves);
    }
Recursively explore the tree to find the leaves that are still reachable
after optimizations.
@param tree the node to check next
@param leaves the list of leaves that were found
storage-api/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java