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

Generic API should require GenericEnumSymbol when writing Avro Enums

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.1
    • Fix Version/s: 1.8.0
    • Component/s: None
    • Labels:
      None
    • Hadoop Flags:
      Incompatible change
    • Release Note:
      Hide
      Previous versions of Avro's Java library allowed String and Java Enum values to be used in the Generic API when writing fields that are Avro Enums. This change makes the Generic API strict by requiring GenericEnumSymbol instances. To ease updating downstream projects it also adds a constructor for GenericData.EnumSymbol that calls toString on a passed Object.
      Show
      Previous versions of Avro's Java library allowed String and Java Enum values to be used in the Generic API when writing fields that are Avro Enums. This change makes the Generic API strict by requiring GenericEnumSymbol instances. To ease updating downstream projects it also adds a constructor for GenericData.EnumSymbol that calls toString on a passed Object.

      Description

      I have a schema like:

      [
      {
        "type": "enum",
        "name": "Gender",
        "symbols": ["M", "F"]
      },
      
      {
        "type" : "record",
        "name" : "Foo",
        "fields" : [
          { "type" : ["Gender", "null"], "name" : "gender" },
          ...
        ]
      }
      ]
      

      I build a record like Foo foo = new Foo(); foo.gender = Gender.M;

      When I go to serialize this, I get:

      Not in union [{"type":"enum","name":"Gender","symbols":["M","F"]},"null"]: M
      	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:482)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:70)
      	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57)
      

        Attachments

        1. AVRO-997.patch
          7 kB
          Sean Busbey
        2. AVRO-997.patch
          7 kB
          Sean Busbey
        3. AVRO-997.patch
          3 kB
          Doug Cutting
        4. AVRO-997.permissive-generic-api.patch
          15 kB
          Sean Busbey

          Issue Links

            Activity

              People

              • Assignee:
                busbey Sean Busbey
                Reporter:
                kimballa Aaron Kimball
              • Votes:
                2 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: