code: private static Filter flatten(Filter root)
    {
      if (root instanceof BooleanFilter) {
        List<Filter> children = new ArrayList<>();
        children.addAll(((BooleanFilter) root).getFilters());
        // iterate through the index, so that if we add more children,
        // they don't get re-visited
        for (int i = 0; i < children.size(); ++i) {
          Filter child = flatten(children.get(i));
          // do we need to flatten?
          if (child.getClass() == root.getClass() && !(child instanceof NotFilter)) {
            boolean first = true;
            List<Filter> grandKids = ((BooleanFilter) child).getFilters();
            for (Filter grandkid : grandKids) {
              // for the first grandkid replace the original parent
              if (first) {
                first = false;
                children.set(i, grandkid);
              } else {
                children.add(++i, grandkid);
              }
            }
          } else {
            children.set(i, child);
          }
        }
        // if we have a singleton AND or OR, just return the child
        if (children.size() == 1 && (root instanceof AndFilter || root instanceof OrFilter)) {
          return children.get(0);
        }
  
        if (root instanceof AndFilter) {
          return new AndFilter(children);
        } else if (root instanceof OrFilter) {
          return new OrFilter(children);
        }
      }
      return root;
    }
docs: https://github.com/apache/hive/blob/branch-2.0/storage-api/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java