You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (Jira)" <ji...@apache.org> on 2020/01/20 14:55:00 UTC

[jira] [Commented] (AVRO-2706) union reading does not use first matching member

    [ https://issues.apache.org/jira/browse/AVRO-2706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17019539#comment-17019539 ] 

Ryan Skraba commented on AVRO-2706:
-----------------------------------

I agree – the behaviour here is not matching the spec, which says that a "matching" schema can include primitive promotion (i.e. {{"long"}} *does* match {{"int"}} and it *is* the first in the list).

 

 

 

> union reading does not use first matching member
> ------------------------------------------------
>
>                 Key: AVRO-2706
>                 URL: https://issues.apache.org/jira/browse/AVRO-2706
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>            Reporter: Roger
>            Priority: Minor
>
> [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)