/** * Check whether a collection of AvroSchema objects contains a given AvroSchema element, resolving * UIDs using the given FijiSchemaTable. * * @param schemaTable FijiSchemaTable with which to resolve schema UIDs. * @param schemaCollection collection of AvroSchemas to check for the presence of the given * element. * @param element AvroSchema for whose presence to check in schemaCollection. * @return whether schemaCollection contains element after resolving UIDs using schemaTable. * @throws IOException in case of an error reading from the schema table. */ public static boolean avroSchemaCollectionContains( final FijiSchemaTable schemaTable, final Collection<AvroSchema> schemaCollection, final AvroSchema element ) throws IOException { for (AvroSchema schema : schemaCollection) { if (avroSchemaEquals(schemaTable, schema, element)) { return true; } } // If none match, return false. return false; }
/** * 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); }
if (!schemaNameEquals(reader, writer)) { return SchemaCompatibilityType.INCOMPATIBLE; if (!schemaNameEquals(reader, writer)) { return SchemaCompatibilityType.INCOMPATIBLE; if (!schemaNameEquals(reader, writer)) { return SchemaCompatibilityType.INCOMPATIBLE; final Field writerField = lookupWriterField(writer, readerField); if (writerField == null) {
final Schema optionalType = AvroUtils.getOptionalType(schema); if (optionalType != null) { return json.isNull() ? null : fromJsonNode(json, optionalType);
/** * 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; }
Preconditions.checkArgument(schema.getType() == Schema.Type.UNION); final Schema optionalType = AvroUtils.getOptionalType(schema); if (null != optionalType) { return (null == value)
/** * 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); }