Avro
  1. Avro
  2. AVRO-1482

in specification, put "null" first in unions

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.7
    • Component/s: doc
    • Labels:
      None

      Description

      Unions with null are a common schema idiom. When a default-value is specified, it is most often null. Default values for unions must be of the type of the first element in the union. So normally, when specifying a union with null, one places the null first so that one can use null as the default value. Folks often make the mistake of specifying null as the default value when it is not the first value in the union. Thus the best practice is to put null as the first element when it is in a union unless you specify a non-null default value.

      Several example schemas in the specification do not put the null first in the union schema. The specification should set a better example, to help folks to avoid this potential confusion. It might also mention this issue more explicitly.

      1. AVRO-1482.patch
        3 kB
        Doug Cutting

        Activity

        Hide
        Doug Cutting added a comment -

        Here's a patch. I'll commit this soon unless there are objections.

        Show
        Doug Cutting added a comment - Here's a patch. I'll commit this soon unless there are objections.
        Hide
        Sean Busbey added a comment -

        +1 looks good to me.

        Show
        Sean Busbey added a comment - +1 looks good to me.
        Hide
        ASF subversion and git services added a comment -

        Commit 1577673 from Doug Cutting in branch 'avro/trunk'
        [ https://svn.apache.org/r1577673 ]

        AVRO-1482. In specification, place null first in unions as best practice.

        Show
        ASF subversion and git services added a comment - Commit 1577673 from Doug Cutting in branch 'avro/trunk' [ https://svn.apache.org/r1577673 ] AVRO-1482 . In specification, place null first in unions as best practice.
        Hide
        Doug Cutting added a comment -

        Thanks for the review, Sean! I committed this.

        Show
        Doug Cutting added a comment - Thanks for the review, Sean! I committed this.
        Hide
        Hudson added a comment -

        SUCCESS: Integrated in AvroJava #447 (See https://builds.apache.org/job/AvroJava/447/)
        AVRO-1482. In specification, place null first in unions as best practice. (cutting: rev 1577673)

        • /avro/trunk/CHANGES.txt
        • /avro/trunk/doc/src/content/xdocs/spec.xml
        Show
        Hudson added a comment - SUCCESS: Integrated in AvroJava #447 (See https://builds.apache.org/job/AvroJava/447/ ) AVRO-1482 . In specification, place null first in unions as best practice. (cutting: rev 1577673) /avro/trunk/CHANGES.txt /avro/trunk/doc/src/content/xdocs/spec.xml

          People

          • Assignee:
            Doug Cutting
            Reporter:
            Doug Cutting
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development