/** * Validates that the provided reader schema can read data written with the provided writer * schemas. * * @param reader schema to check. * @param writers that must be compatible with the provided reader schema. * @return a list of compatibility results. */ public static SchemaSetCompatibility checkReaderCompatibility( Schema reader, Iterator<Schema> writers) { final List<SchemaPairCompatibility> results = Lists.newArrayList(); while (writers.hasNext()) { // Check compatibility between each reader/writer pair. results.add(checkReaderWriterCompatibility(reader, writers.next())); } return new SchemaSetCompatibility(results); }
/** * Validates each of a set of reader schemas against each of a set of writer schemas. * * @param readerSchemas the set of reader schemas to validate. * @param writerSchemas the set of writer schemas to validate. * @return a list of error messages corresponding to each invalid combination of a reader and * writer schema. Returns an empty list if all reader and writers schemas are compatible. */ private static List<String> validateReaderWriterSchemas( List<Schema> readerSchemas, List<Schema> writerSchemas) { final List<String> incompatabilityMessages = Lists.newArrayList(); for (Schema readerSchema : readerSchemas) { // Check that each reader schema can read records written by all writer schemas. final SchemaSetCompatibility compat = AvroUtils.checkReaderCompatibility(readerSchema, writerSchemas.iterator()); if (compat.getType() == SchemaCompatibilityType.INCOMPATIBLE) { for (SchemaPairCompatibility pairCompat : compat.getCauses()) { if (pairCompat.getType() == SchemaCompatibilityType.INCOMPATIBLE) { incompatabilityMessages.add( String.format("Reader schema: %s is incompatible with writer schema: %s.", pairCompat.getReader(), pairCompat.getWriter())); } } } } return incompatabilityMessages; }
/** * Validates that the provided reader schemas can be used to decode data written with the provided * writer schema. * * @param readers that must be able to be used to decode data encoded with the provided writer * schema. * @param writer schema to check. * @return a list of compatibility results. */ public static SchemaSetCompatibility checkWriterCompatibility( Iterator<Schema> readers, Schema writer) { final List<SchemaPairCompatibility> results = Lists.newArrayList(); while (readers.hasNext()) { // Check compatibility between each reader/writer pair. results.add(checkReaderWriterCompatibility(readers.next(), writer)); } return new SchemaSetCompatibility(results); }