Expand description
Check if the reader’s schema is compatible with the writer’s schema.
To allow for schema evolution, Avro supports resolving the writer’s schema to the reader’s schema.
To check if this is possible, SchemaCompatibility can be used. For the complete rules see
the specification.
There are three levels of compatibility.
- Fully compatible schemas (
Ok(Compatibility::Full))
For example, an integer can always be resolved to a long:
let writers_schema = Schema::array(Schema::Int).build();
let readers_schema = Schema::array(Schema::Long).build();
assert_eq!(SchemaCompatibility::can_read(&writers_schema, &readers_schema), Ok(Compatibility::Full));- Incompatible schemas (
Err)
For example, a long can never be resolved to an int:
let writers_schema = Schema::array(Schema::Long).build();
let readers_schema = Schema::array(Schema::Int).build();
assert!(SchemaCompatibility::can_read(&writers_schema, &readers_schema).is_err());- Partially compatible schemas (
Ok(Compatibility::Partial))
For example, a union of a string and integer is only compatible with an integer if an integer was written:
let writers_schema = Schema::union(vec![Schema::Int, Schema::String])?;
let readers_schema = Schema::Int;
assert_eq!(SchemaCompatibility::can_read(&writers_schema, &readers_schema), Ok(Compatibility::Partial));Structs§
- Schema
Compatibility - Check if two schemas can be resolved.
Enums§
- Compatibility
- How compatible two schemas are.