-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Hi!
I'm trying to use rsgen-avro to generate code for parsing Avro messages published on a Kafka topic.
The schema(ta) for the topic is stored in a Confluent schema registry.
When I check the latest schema for compatibility with older versions of the schema it succeeds if i
- Fetch latest schema from registry (get-schema-by-version API)
- Check compatibility with older versions with the returned schema verbatim in the request. (test-compatibility-against-a-particular-schema-subject-version API)
However, it fails if I:
- Fetch latest schema from registry (as above)
- Generate code with
rsgen-avro; only non-default beingimplement_avro_schema(ImplementAvroSchema::CopyBuildSchema) - Check compatibility with older versions with the schema returned by either
T::get_schema().canonical_form()orserde_json::to_string(&T::get_schema()).
As far as I can tell, all the errors I encounter is due to READER_FIELD_MISSING_DEFAULT_VALUE. The canonical form conversion strips default and such (which I think is according to spec), but it causes the generated schema not to be backwards compatible with earlier versions of the schema.
Similarly this:
// `client` being the schema registry client
let latest_schema = client.latest_schema().await?;
let prev_schema = client.schema_version(latest_schema.version - 1).await?;
let prev_parsed = apache_avro::Schema::parse_str(&prev_schema.schema)?;
let latest_parsed = apache_avro::Schema::parse_str(&latest_schema.schema)?;
// can_read(writer_schema, reader_schema) -- "I" only care about backwards compatibility, not full compatibility.
eprintln!("{:?}", apache_avro::schema_compatibility::SchemaCompatibility::can_read(&prev_parsed, &T::get_schema()));
eprintln!("{:?}", apache_avro::schema_compatibility::SchemaCompatibility::can_read(&prev_parsed, &latest_parsed));
prints
Err(Incompatible schemata! Field 'xxx' in reader schema does not match the type in the writer schema: Incompatible schemata! Field 'yyy' in reader schema does not match the type in the writer schema)
Ok(())
I fear a change to apache-avro might be required to fix this, but if versioned schema compatibility is considered a valid use case here, it might be worth addressing.
It might be worth noting that I am relatively new to the world of Avro, so I might have gotten something wrong :)