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

Records with unions with self references fail to parse.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.8.1
    • 1.9.0
    • java
    • None
    • Java 1.8.0_152-b1

    Description

      Records with unions with self references fail to parse.

      The example below fails to parse with "Type not supported: Node"

      [
        {
          "namespace": "tree",
          "type": "record",
          "name": "Node",
          "fields": [
            {
              "name": "left",
              "type": [
                "null",
                {
                  "type": "Node"
                }
              ],
              "default": null
            },
            {
              "name": "right",
              "type": [
                "null",
                {
                  "type": "Node"
                }
              ],
              "default": null
            }
          ]
        }
      ]
       

      When we don't allow nullability it parses successfully:

      [
        {
          "namespace": "tree",
          "type": "record",
          "name": "Node",
          "fields": [
            {
              "name": "left",
              "type": "Node"
            },
            {
              "name": "right",
              "type": "Node"
            }
          ]
        }
      ]
       

      The root cause: When the second element of the union, {"type":"Node"}, is parsed there is no path that can successfully handle the JsonNode.

      The solution is to add this logic to the Schema.parse(JsonNode schema, Names names) method:

            } else {  //For unions with self reference
              Name nameFromType = new Name(type, names.space);
              if (names.containsKey(nameFromType)) {
                return names.get(nameFromType);
              }
              throw new SchemaParseException("Type not supported: "+type);
            }
      

      Pull request attached

      Attachments

        Activity

          People

            dkulp Daniel Kulp
            jeff.maxwell Jeff Maxwell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: