Skip to content

GH-832: [Avro] Use readString in AvroStringConsumer - #1520

Merged
jbonofre merged 1 commit into
apache:mainfrom
dragonknightk:fix-avro-string-consumer-readstring-832
Nov 24, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
dragonknightk:fix-avro-string-consumer-readstring-832

Conversation

@dragonknightk

@dragonknightk dragonknightk commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What's Changed

AvroStringConsumer read string fields with Decoder.readBytes. That works with BinaryDecoder, because the binary encoding for string and bytes is the same. ResolvingDecoder checks the reader schema and throws AvroTypeException: "Attempt to process a bytes when a string was expected." ValidatingDecoder throws the same error, and this change fixes both.

The consumer now calls Decoder.readString and copies the Utf8 bytes into the VarCharVector, reusing the Utf8 instance the same way the old code reused a ByteBuffer.

Closes #832.

AI Disclosure

Human-led contribution. Grok Bot, working for dragonknightk, assisted with this change, including the code, tests, and description. All submitted content was reviewed by a human before submission.

## What's Changed

AvroStringConsumer read string fields with Decoder.readBytes. That works with BinaryDecoder, because the binary encoding for string and bytes is the same. ResolvingDecoder checks the reader schema and throws AvroTypeException: "Attempt to process a bytes when a string was expected." ValidatingDecoder throws the same error, and this change fixes both.

The consumer now calls Decoder.readString and copies the Utf8 bytes into the VarCharVector, reusing the Utf8 instance the same way the old code reused a ByteBuffer.

The new test reads "v1", an empty string and a non-ASCII string through a ResolvingDecoder and checks the vector holds the same values; the empty string after a longer value and the multi-byte characters check that only the valid bytes of the reused Utf8 are copied.

Closes issue 832.

Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com>
@github-actions

This comment has been minimized.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Nov 24, 2026
@github-actions github-actions Bot added this to the 20.1.0 milestone Nov 24, 2026

@jbonofre jbonofre 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.

LGTM, thanks @dragonknightk!

Switching AvroStringConsumer to Decoder.readString(Utf8) fixes ResolvingDecoder / ValidatingDecoder schema checking while preserving Utf8 buffer reuse and copying cacheUtf8.getByteLength() bytes into VarCharVector. The regression test nicely covers ResolvingDecoder, shrinking to an empty string, and multi-byte UTF-8.

I verified adapter/avro tests, checkstyle, and spotless locally. All good 😄

@jbonofre
jbonofre merged commit 66d7085 into apache:main Nov 24, 2026
21 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avro adapter: AvroStringConsumer should use readString instead of readBytes

3 participants