code: private Schema flattenUnion(Schema schema, boolean shouldPopulateLineage, boolean flattenComplexTypes) {
      Preconditions.checkNotNull(schema);
      Preconditions.checkArgument(Schema.Type.UNION.equals(schema.getType()));
  
      Schema flattenedSchema;
  
      List<Schema> flattenedUnionMembers = new ArrayList<>();
      if (null != schema.getTypes() && schema.getTypes().size() > 0) {
        for (Schema oldUnionMember : schema.getTypes()) {
          if (flattenComplexTypes) {
            // It's member might still recursively contain records
            flattenedUnionMembers.add(flatten(oldUnionMember, shouldPopulateLineage, flattenComplexTypes));
          } else {
            flattenedUnionMembers.add(oldUnionMember);
          }
        }
      }
      flattenedSchema = Schema.createUnion(flattenedUnionMembers);
  
      return flattenedSchema;
    }
docs: *
  Flatten Union Schema
  @param schema Union Schema to flatten
  @param shouldPopulateLineage If lineage information should be tagged in the field, this is true when we are
  un-nesting fields
  @param flattenComplexTypes Flatten complex types recursively other than Record and Option
  @return Flattened Union Schema