Backport #745 (+ follow-ups) to 2.x: Avro union resolution and schema default precision - #754
Merged
Merged
Conversation
Three independent Avro bugs, backported from the 3.x work on #745: * `_resolveBigDecimalIndex()` tested `Type.DOUBLE` twice (the first test was meant to be String/Bytes), so a `BigDecimal` in a union was always written as `double` even when a lossless branch existed. Rank branches by fidelity instead: "decimal" Bytes/Fixed, then String, then Double. Plain `bytes`/`fixed` are skipped, since conversion needs the logical type and would otherwise NPE. * `RootContext.createChildObjectContext()` sent every UNION to Record handling, so a root union containing a `map` failed. Resolve via `_createObjectContext()`, which routes MAP to `MapWriteContext`. * `AvroFieldDefaulters` built `FloatDefaults` for `int` and `long` schema defaults, truncating values past float's 24-bit mantissa. Also re-reads `type` after union resolution in `_createRecord()`, so its error message names the resolved type. Test class renamed to conventional camel case, matching 3.x. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Backport of #745 to the 2.x line, including the follow-up fixes in #753. All four bugs are
present on
2.xunfixed.Ported the corrected end state rather than #745 as merged, since #745 alone introduces a
BigDecimal/plain-bytesNPE that #753 fixes.Changes
ser/AvroWriteContext.java—_resolveBigDecimalIndex()testedType.DOUBLEtwice; thefirst test was meant to be String/Bytes. A
BigDecimalin a union was therefore always writtenas
double, even when a lossless branch existed. Branches are now ranked by fidelity:decimalbytes/fixed, thenString, thenDouble. Plainbytes/fixedare skipped —conversion requires the logical type and would otherwise NPE.
ser/RootContext.java—createChildObjectContext()sent everyUNIONto Record handling,so a root union containing a
mapfailed. Now resolves via_createObjectContext(), whichroutes
MAPtoMapWriteContext.deser/AvroFieldDefaulters.java—intandlongschema defaults were built asFloatDefaults, truncating values past float's 24-bit mantissa (20000001→20000000,9007199254740993→...992).Also re-reads
typeafter union resolution in_createRecord(), so its error message namesthe resolved type.