Skip to content

AvroSchema implementation and schema registries #92

@gsson

Description

@gsson

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

  1. Fetch latest schema from registry (get-schema-by-version API)
  2. 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:

  1. Fetch latest schema from registry (as above)
  2. Generate code with rsgen-avro; only non-default being implement_avro_schema(ImplementAvroSchema::CopyBuildSchema)
  3. Check compatibility with older versions with the schema returned by either T::get_schema().canonical_form() or serde_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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions