flavray / avro-rs

Avro client library implementation in Rust
MIT License
169 stars 95 forks source link

Add support for deduplicating definitions in schemas #202

Closed travisbrown closed 2 years ago

travisbrown commented 2 years ago

This is a sketch of an approach that could be used to fix #182.

The problem is that the library replaces every name reference in a schema with the full definition, and the Avro tooling for Java (and possibly other platforms) considers these "redefinitions" and fails when it sees them.

I think there are two ways to fix this:

  1. Add a reference variant to the schema ADT and bundle a map from references to definitions with the schema type.
  2. Deduplicate definitions during serialization.

This PR does the latter, which is much less invasive. When the schema is being written to the Avro file, it only writes the first definition for each record type, and replaces the rest with the full name.

This PR is a quick sketch that is currently untested and only handles records (not enums or fixeds), since I just wanted to make sure it solves the problem in my case (at first glance it seems to) and to check whether a change like this would be considered.

martin-g commented 2 years ago

@travisbrown You might want to read this - https://github.com/flavray/avro-rs/pull/99#issuecomment-1017195592

travisbrown commented 2 years ago

@martin-g Ah, thanks. I saw the general status change but not that specific fix. I'll take a closer look.