Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for decoding with avro alias #171

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

trdw
Copy link
Contributor

@trdw trdw commented Nov 17, 2023

Problem: We want to read some data using Avro evolution mechanism for field renaming. Current behavior does not account for AvroAlias annotation.

Proposed solution: fieldValue() function iterates through list of possible field names, starting with the resolvedFieldName. For each attempt, if record contains the field name, return the value returned from record.get(...), else continue.

Closes #170

@Chuckame
Copy link
Contributor

Hello, sorry for the delay, I'll take a lot at it to see if it is not changing some other behavior. Thanks for the PR 🚀

@Chuckame Chuckame requested review from thake and Chuckame January 22, 2024 13:12
@Chuckame
Copy link
Contributor

Chuckame commented Jan 22, 2024

AFAIK, without your PR, we are able to decode an old schema written with an alias while the kotlin data class uses the real field name (not alias).

What is not working is when you read a new schema where the kotlin data class is using an alias for its field name instead of the real field name. That's because apache avro library "normalize" the field name, and whatever the alias name or the real name, it creates a GenericRecord using field's real name (that is totally normal).

I don't see any particular issue, I approve it. @thake it's ok for you also ?

@Chuckame
Copy link
Contributor

Side note: We should cache somewhere with a map like Map<alias, real name> to prevent useless aliases iterations. Let's plan it for v2 @thake

@Chuckame Chuckame merged commit 53a9b7e into avro-kotlin:main Jan 27, 2024
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.

RecordDecoder including aliases from AvroAlias annotation for possible field names
2 participants