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

Allow enums to be "promoted" to strings

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: java, spec
    • Labels:
      None

      Description

      We should consider adding a resolution rule that can promote an enum to a string using the enum's symbol.

      I have an Avro schema that has a field with an enum type. However, I have realized that an enum is not the type I actually wanted. I would much rather have the type of the field be a string. I went to change this, but of course this type of change (enum -> string) is not within the bounds of Avro's schema evolution. Therefore a reader with this changed schema is not be able to read an object written with the old schema.

      For example, if the writer schema was:

      enum Colour {
      RED, YELLOW, GREEN
      }
      protocol stoplight {
      Colour colour;
      }

      And the reader schema was:

      protocol stoplight {
      string colour;
      }

      Then when you access the colour field of your object, you get the string representation of the enum value's symbol .

      For example, Colour.RED => "RED", Colour.YELLOW => "YELLOW", Colour.GREEN => "GREEN"

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              movermeyer Michael Overmeyer
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: