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

[jira] [Updated] (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:all-tabpanel ]

Roger updated AVRO-2706:
------------------------
    Description: 
[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}}


  was:
[Here|https://gist.github.com/rogpeppe/5faf971eec51f3dbd316bb71d6d5dccc] is a JSON representation of a test case that fails with the Java implementation of Avro.

To reproduce on the command line with avro-tools, you'll need a version of avro-tools with https://github.com/apache/avro/pull/785 committed. I've used the name "avro" as a synonym for running the avro-tools jar under the Java VM:

 	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 produces:

    {"F":{"int":999}}

whereas I'd expect to see "long", because the first matching item in the union is "long".



> 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: 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)