[
https://issues.apache.org/jira/browse/AVRO-4355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18121744#comment-18121744
]
Robert Yokota commented on AVRO-4355:
-------------------------------------
Closing for now. The checker change is correct for an exact renamed reader. But
the decoder applies aliases twice (FastReaderBuilder/GenericDatumReader, then
Resolver.resolve), so a swapped schema read by any other reader, e.g. one that
adds a field, silently reverses the swap. Making the checker accept swaps would
let those schemas register. The decoder would need additional fixing.
> SchemaCompatibility throws on fields whose names are swapped by aliases,
> which the decoder reads correctly
> -----------------------------------------------------------------------------------------------------------
>
> Key: AVRO-4355
> URL: https://issues.apache.org/jira/browse/AVRO-4355
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.12.2
> Reporter: Robert Yokota
> Assignee: Robert Yokota
> Priority: Critical
> Labels: pull-request-available
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> h3. Summary
>
>
> When a reader swaps the names of two fields using aliases,
> SchemaCompatibility throws instead of returning a result, even though the
> decoder reads the swap correctly. Swapping
> the names of two record types with aliases is handled correctly by both.
>
>
>
>
>
> h3. Steps to reproduce (1.12.1 and master)
>
>
> Writer:
>
>
> {code:json}
>
>
> {"type":"record","name":"R","fields":[
>
>
> {"name":"a","type":"int"},
>
>
> {"name":"b","type":"string"}]}
>
>
> {code}
>
>
> Reader:
>
>
> {code:json}
>
>
> {"type":"record","name":"R","fields":[
>
>
> {"name":"b","type":"int","aliases":["a"]},
>
>
> {"name":"a","type":"string","aliases":["b"]}]}
>
>
> {code}
>
>
> {code:java}
>
>
> SchemaCompatibility.checkReaderWriterCompatibility(reader, writer);
>
>
> {code}
>
>
>
>
>
> h3. Actual
>
>
> An AvroRuntimeException is thrown, rather than a compatibility result being
> returned:
>
> {noformat}
>
>
> Reader record field b type:INT pos:0 matches multiple fields in writer
> record schema
>
>
> {"type":"record","name":"R","fields":[{"name":"a","type":"int"},{"name":"b","type":"string"}]}
>
>
> {noformat}
>
>
>
>
>
> h3. Expected
>
>
> COMPATIBLE. Reading data written with the writer schema through
> GenericDatumReader, with this reader schema, works as intended: the old a
> goes into b, and the old b goes into a.
>
>
>
> h3. Comparison with record names
>
>
> Swapping two record names with aliases inside a union (A becomes B aliased
> A, and B becomes A aliased B) is reported as compatible by
> SchemaCompatibility, and the decoder reads
> it correctly. Only field name swaps are rejected.
>
>
>
>
>
> The same happens with a three-field rotation (b aliases a, c aliases b, a
> aliases c), and in nested records.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)