rayokota opened a new pull request, #4019:
URL: https://github.com/apache/avro/pull/4019
…ility
<!--
*Thank you very much for contributing to Apache Avro - we are happy that you
want to help us improve Avro. To help the community review your contribution in
the best possible way, please go through the checklist below, which will get
the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Avro a
hassle. In order to uphold a high standard of quality for code contributions,
while at the same time managing a large number of contributions, we need
contributors to prepare the contributions well, and give reviewers enough
contextual information for the review. Please also understand that
contributions that do not follow this guide will take longer to review and thus
typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA
issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are
made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "AVRO-XXXX: [component] Title of the
pull request", where *AVRO-XXXX* should be replaced by the actual issue number.
The *component* is optional, but can help identify the correct reviewers
faster: either the language ("java", "python") or subsystem such as "build" or
"doc" are good candidates.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests. You can [build the
entire project](https://github.com/apache/avro/blob/main/BUILD.md) or just the
[language-specific
SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
- Each pull request should address only one issue, not mix up code from
multiple issues.
- Each commit in the pull request has a meaningful commit message
(including the JIRA id)
- Every commit message references Jira issues in their subject lines. In
addition, commits follow the guidelines from [How to write a good git commit
message](https://chris.beams.io/posts/git-commit/)
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue
reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
-->
## What is the purpose of the change
When a reader swaps or rotates field names using aliases (for example `b`
aliased `a`, and `a` aliased `b`), `SchemaCompatibility` throws
`AvroRuntimeException` ("Reader record
field b ... matches multiple fields in writer record schema"). The decoder
reads the same schemas correctly. This fixes AVRO-XXXX.
`lookupWriterField` collects the writer field with the reader field's own
name, plus each writer field named by one of its aliases, and throws when it
finds more than one. The
decoder instead goes through `Schema.applyAliases`, which renames the
writer's `a` to `b` and its `b` to `a`, so each reader field reads the writer
field its alias names. Record
name swaps already work in both, because the checker compares type names
at each location.
The record-fields check now uses a new package-private
`lookupWriterField(writer, reader, readerField)`, which can see the whole
reader record. If the writer field with the
reader field's own name is claimed by another reader field's alias, the
reader field takes the writer field its own alias names. That is exactly when
`applyAliases` renames that
writer field away.
Every other case falls through to the existing `lookupWriterField(Schema,
Field)`, whose behavior is unchanged:
- A reader field aliasing a writer field that no other alias frees still
throws. The decoder fails there too, with "Duplicate field".
- Renaming a field and reusing its old name for a new field is checked as
before.
## Verifying this change
This change added tests to `TestSchemaCompatibility`:
- A two-field swap is compatible, and decoding with `GenericDatumReader`
gives the same pairing.
- A three-field rotation is compatible.
- A swap inside a nested record is compatible.
- Swapped fields are compared against the writer fields their aliases
name, so a type swapped as well is reported as `TYPE_MISMATCH`.
- A reader field aliasing a writer field that no other alias frees still
throws.
The swap and rotation tests fail without the change. All
`TestSchemaCompatibility*` tests pass (82).
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]