Repository navigation
Conversation
Signed-off-by: 付典 <fudianchn@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
What
Enable single-object encoding on a writer.
Each root value gets its own header, even in a sequence. The default is raw Avro.
Why
Callers can send Jackson output directly to Apache Avro's
BinaryMessageDecoder. The corresponding reader landed in #905.How
The generator caches a 10-byte header using the marker bytes and the little-endian fingerprint of the original writer schema from @Vineet829's #905. The same encoder writes the header and datum. Writing a value with
AVRO_FILE_OUTPUTalso enabled raises an exception.Explicit flush drains buffered messages even after the option is switched off. On close, the generator drains pending bytes and closes any stream it owns, even if the final write fails.
Root cause
Feature request. The writer previously supported raw Avro and object container files.
Testing
All 25 focused tests passed.
./mvnw -pl avro -Dtest=SingleObjectWrite172Test,SingleObjectEncoding343Test,FileFormatTest testThe default writer still writes 32 integers (88 bytes) in one underlying write on close. The six paired JMH runs were too noisy to establish equivalent throughput.
Verification of the original issue
On the base branch, Apache Avro rejected the record because its header was missing.
With the option enabled, Apache Avro 1.12.2 reads back
ids = [3, 5]. Both encoders produce identical bytes. Two null values produce 20 bytes. An empty sequence produces zero.Fixes #172