/** * Merges two {@link Schema} instances or returns {@code null}. * <p> * The two schemas are merged if they are the same type. Records are merged * if the two records have the same name or have no names but have a * significant number of shared fields. * <p> * @see {@link #mergeOrUnion} to return a union when a merge is not possible. * * @param left a {@code Schema} * @param right a {@code Schema} * @return a {@code Schema} for both types */ private static Schema mergeOrUnion(Schema left, Schema right) { Schema merged = mergeOnly(left, right); if (merged != null) { return merged; } return union(left, right); }
/** * Merges two {@link Schema} instances if they are compatible. * <p> * Two schemas are incompatible if: * <ul> * <li>The {@link Schema.Type} does not match.</li> * <li>For record schemas, the record name does not match</li> * <li>For enum schemas, the enum name does not match</li> * </ul> * <p> * Map value and array element types will use unions if necessary, and union * schemas are merged recursively. * * @param left a {@code Schema} * @param right a {@code Schema} * @return a merged {@code Schema} * @throws IncompatibleSchemaException if the schemas are not compatible */ public static Schema merge(Schema left, Schema right) { Schema merged = mergeOnly(left, right); IncompatibleSchemaException.check(merged != null, "Cannot merge %s and %s", left, right); return merged; }
Schema merged = mergeOnly(next, right); if (merged != null) { types.add(merged);