[ https://issues.apache.org/jira/browse/AVRO-2707?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ryan Skraba resolved AVRO-2707. ------------------------------- Resolution: Duplicate > union reading does not use first matching member > ------------------------------------------------ > > Key: AVRO-2707 > URL: https://issues.apache.org/jira/browse/AVRO-2707 > Project: Apache Avro > Issue Type: Bug > Reporter: Roger > Priority: Major > > [Here|https://gist.github.com/rogpeppe/5faf971eec51f3dbd316bb71d6d5dccc] is a > JSON representation of a test case that produces unexpected behaviour under > the Java Avro implementation. > The test verifies that the JSON data in inData with encoding inSchema > produces outData when read as outSchema. > The specification says: "The first schema in the reader's union that matches > the selected writer's union schema" which to me says that the output should > be a long, because long is before int in the reader's union and long matches > int. > To reproduce on the command line, you'll need a version of avro-tools with > [this PR applied|https://github.com/apache/avro/pull/785], then run: > echo '{"F":{"int":999}}' | > avro fromjson --schema > '{"name":"R","type":"record","fields":[{"name":"F","type":["int","string"],"default":1234}]}' > - | > avro tojson --reader-schema > '{"name":"R","type":"record","fields":[{"name":"F","type":["long","int","string"],"default":1234}]}' > - > This prints: > {"F":{"int":999}} > but I'd expect to see this: > {"F":{"long":999}} -- This message was sent by Atlassian Jira (v8.3.4#803005)