Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2706

union reading does not use first matching member

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java
    • None

    Description

      Here 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, 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}}

      Attachments

        Activity

          People

            Unassigned Unassigned
            rogpeppe Roger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: