Skip to content

feat: Expose the capability to do headerless avro encoding with serde - #193

Merged
martin-g merged 4 commits into
apache:mainfrom
allenbenz:add-serde-dataum
May 6, 2025
Merged

martin-g merged 4 commits into
apache:mainfrom
allenbenz:add-serde-dataum

Conversation

@allenbenz

Copy link
Copy Markdown
Contributor

My use case is I'm serializing large counts of individual objects to publish to google pubsub in an async setting where the "real" work being done elsewhere is so inexpensive to do that overhead dominates performance concerns.

Basically I want to use avro-rs to serialize with minimal allocation/cloning and I must not have headers or markers in the output.

Specifics you can skip:

google's pubsub uses a stripped down version of the single record format (v1) - it is without any of the headers or markers, it only wants avro's raw binary encoding. Topics are configured with a the avro schema and the format so they are assumed when trying to publish to that topic.

The high volume makes it undesirable to construct a SpecificSingleObjectWriter per call as it clones the avro schema.
The async setting prevents sharing the SpecificSingleObjectWriter safely as write_ref mutably borrows self.

My current workaround is using SyncUnsafeCell to share a mutable reference to a SpecificSingleObjectWriter that has already written a header once is not future proof in the slightest.

I'm not in love with write_avro_datum_ref as the name but it was close to the language of SpecificSingleObjectWriter.write_ref and to_avro_datum. I had write_avro_datum_ref take in a writer rather than make a Vec since that seems more sensible for serialization/allows it to be used in SpecificSingleObjectWriter.

@martin-g martin-g left a comment

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.

Please add some unit tests!

Comment thread avro/src/writer.rs Resolved
Comment thread avro/src/writer.rs Resolved
formatted code
fixed up a couple comments
@martin-g martin-g changed the title Expose the capability to do headerless avro encoding with serde feat: Expose the capability to do headerless avro encoding with serde May 5, 2025
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Comment thread avro/src/writer.rs Resolved
@martin-g
martin-g merged commit d82d820 into apache:main May 6, 2025
@martin-g

martin-g commented May 6, 2025

Copy link
Copy Markdown
Member

Thank you for the contribution, @allenbenz !

@allenbenz

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews @martin-g

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