public static TypeInfo getCommonClassForStruct(StructTypeInfo a, StructTypeInfo b,
      BiFunction<TypeInfo, TypeInfo, TypeInfo> commonClassFunction) {
    if (a == b || a.equals(b)) {
      return a;
    }

    List<String> names = new ArrayList<String>();
    List<TypeInfo> typeInfos = new ArrayList<TypeInfo>();

    Iterator<String> namesIterator = a.getAllStructFieldNames().iterator();
    Iterator<String> otherNamesIterator = b.getAllStructFieldNames().iterator();

    // Compare the field names using ignore-case semantics
    while (namesIterator.hasNext() && otherNamesIterator.hasNext()) {
      String name = namesIterator.next();
      if (!name.equalsIgnoreCase(otherNamesIterator.next())) {
        return null;
      }
      names.add(name);
    }

    // Different number of field names
    if (namesIterator.hasNext() || otherNamesIterator.hasNext()) {
      return null;
    }

    // Compare the field types
    List<TypeInfo> fromTypes = a.getAllStructFieldTypeInfos();
    List<TypeInfo> toTypes = b.getAllStructFieldTypeInfos();
    for (int i = 0; i < fromTypes.size(); i++) {
      TypeInfo commonType = commonClassFunction.apply(fromTypes.get(i), toTypes.get(i));
      if (commonType == null) {
        return null;
      }
      typeInfos.add(commonType);
    }

    return TypeInfoFactory.getStructTypeInfo(names, typeInfos);
  }
Find a common class that objects of both StructTypeInfo a and StructTypeInfo b can
convert to. This is used for places other than comparison.

@return null if no common class could be found.
ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java