public static SchemaDifference getSchemaDiff(Collection<FieldSchema> minuendCollection,
                                               Collection<FieldSchema> subtrahendCollection, boolean bothDirections) {
    SchemaDifference difference = new SchemaDifference();

    for (FieldSchema first : minuendCollection) {
      boolean found = false;
      for (FieldSchema second : subtrahendCollection) {
        if (Objects.equals(first.getName(), second.getName())) {
          found = true;
          if (!Objects.equals(first.getType(), second.getType())) {
            difference.addTypeChanged(first);
          }
          if (!Objects.equals(first.getComment(), second.getComment())) {
            difference.addCommentChanged(first);
          }
        }
      }
      if (!found) {
        difference.addMissingFromSecond(first);
      }
    }

    if (bothDirections) {
      SchemaDifference otherWay = getSchemaDiff(subtrahendCollection, minuendCollection, false);
      otherWay.getMissingFromSecond().forEach(difference::addMissingFromFirst);
    }

    return difference;
  }
Returns a SchemaDifference containing those fields which are present in only one of the collections, as well as
those fields which are present in both (in terms of the name) but their type or comment has changed.
@param minuendCollection Collection of fields to subtract from
@param subtrahendCollection Collection of fields to subtract
@param bothDirections Whether or not to compute the missing fields from the minuendCollection as well
@return the difference between the two schemas
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java