Skip to content

feat!: Rework SpecificSingleObjectWriter - #445

Merged
Kriskras99 merged 3 commits into
apache:mainfrom
Kriskras99:feat/resolve
Jan 27, 2026
Merged

Kriskras99 merged 3 commits into
apache:mainfrom
Kriskras99:feat/resolve

Conversation

@Kriskras99

Copy link
Copy Markdown
Contributor

The first commit changes ResolvedSchema and ResolvedOwnedSchema to use the same logic for resolving.
ResolvedOwnedSchema now also uses a self-referential struct when resolving the schema, so it does not need to clone all named schemas contained in it.

The second commit contains the rework of SpecificSingleObjectWriter

It now resolves the schema and caches it. It also no longer uses GenericSingleObjectWriter for the header and does it directly. This removes the need for a buffer.

This is a breaking change:

  • SpecificSingleObjectWriter::with_capcity has been removed.
  • write_avro_datum_ref now also takes a names: &NamesRef argument

This also fixes a bug in reader::Block::read_writer_schema where it unnecessarily parses the schemata twice.

Closes #439

`ResolvedOwnedSchema` now uses a self-referential struct when resolving the schema, so it does not need to clone all named schemas contained in it.

This also fixes a bug in `reader::Block::read_writer_schema` where it unnecessarily parses the schemata twice.
It now resolves the schema and caches it. It also no longer uses `GenericSingleObjectWriter` for the header and does it directly. This removes the need for a buffer.

This is a breaking change:
- `SpecificSingleObjectWriter::with_capcity` has been removed.
- `write_avro_datum_ref` now also takes a `names: &NamesRef` argument
Comment thread avro/tests/serde_human_readable_true.rs Resolved
Comment thread avro/src/writer.rs
.write_all(&self.header)
.map_err(Details::WriteBytes)?;
let value: Value = data.into();
let bytes = write_value_ref_owned_resolved(&self.resolved, &value, writer)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails then the writer will contain the already written header.
How about something like:

let mut buffer = Vec::new();
let bytes = write_value_ref_owned_resolved(&self.resolved, &value, &mut buffer)?;
writer.write_all(&self.header).map_err(Details::WriteBytes)?;
writer.write_all(&buffer).map_err(Details::WriteBytes)?;
Ok(bytes + self.header.len())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer.write_all(&buffer) can also fail partway through.

I don't think this is worth the performance penalty.

@Kriskras99
Kriskras99 merged commit cc37970 into apache:main Jan 27, 2026
@Kriskras99
Kriskras99 deleted the feat/resolve branch January 27, 2026 19:34
@martin-g martin-g added this to the 0.22.0 milestone Jan 27, 2026
@Kriskras99 Kriskras99 mentioned this pull request Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants