private static int lookupOrAdd(List<RexNode> list, RexNode element) {
    for (int ordinal = 0; ordinal < list.size(); ordinal++) {
      if (list.get(ordinal).toString().equals(element.toString())) {
        return ordinal;
      }
    }
    list.add(element);
    return list.size() - 1;
  }
Finds the ordinal of an element in a list, or adds it.

@param list    List
@param element Element to lookup or add
@return Ordinal of element in list
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveAggregateReduceFunctionsRule.java