Repository navigation
Conversation
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.
What is the purpose of the change
This PR fixes AVRO-4361: the collection size guard (AVRO-4241, AVRO-4300,
AVRO-4324) rejects valid data when the reader's array element or map value
schema has a larger minimum encoded size than the writer's. Examples are a
field added with a default,
intpromoted todouble, ornullread as anullable union. The guard computed the minimum from the reader's schema, but
the bytes were written with the writer's schema.
Fast reader (
FastReaderBuilder.createArrayReader): the writer's arrayschema is available as
action.writer, so the guard now uses the writer'selement type. The guard stays exact.
Classic and reflect readers (
GenericDatumReader,ReflectDatumReader):only the reader's element schema is available while reading. A new
minBytesToRead(Schema)keeps the existing exact bound(
minBytesPerElement) when the writer's and reader's schemas are equal. Thatcheck is computed once per reader and reset by
setSchema/setExpected.When the schemas differ, it uses a new
minResolvedBytesPerElement: theminimum size of any writer's schema that resolves to the reader's.
floatanddoublecount 1, since they may be promoted fromintorlong.fixedkeeps its size.This bound is never larger than the exact one, so a type that was capped as
zero-byte is still capped. And it is 0 whenever a writer's value could be 0
bytes, so valid data is never rejected. The zero-byte allocation cap is now
chosen from the same bound, for arrays and maps.
When the schemas differ, the classic and reflect guards are looser than the
exact bound, but still bound a declared count by the bytes remaining.
ensureAvailableCollectionBytes(Decoder, long, Schema)is unchanged; itsJavadoc now says to pass the writer's element schema. A protected
ensureAvailableCollectionBytes(Decoder, long, int)overload is added forReflectDatumReader.Verifying this change
New tests, each run on both the fast and classic readers where applicable:
TestGenericDatumReadertestMinResolvedBytesPerElement: the resolved bound for promotions,unions,
fixed, and records with defaulted fields.arrayOfRecordsWithAddedDefaultFieldDecodes: the reported case.arrayWithPromotedElementTypeDecodes:int,longandfloatread asdouble.mapWithPromotedValueTypeDecodesarrayOfNullsReadAsNullableUnionDecodesresolvedArrayRejectsHugeCount: the guard still rejects a huge declaredcount when resolving.
equalSchemasKeepExactBound: equal but distinct schema instances keep theexact bound.
TestReflectDatumReader.read_arrayWithPromotedElementTypeWithout the fix, the five decode tests fail with the reported
EOFException: Collection claims ... bytes are available.Documentation