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

Union behavior not consistent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 1.6.1, 1.6.2
    • None
    • python

    Description

      Python's union does not respect the order in which type is specified.

      For following schema:

      {"type":"map","values":["int","long","float","double","string","boolean"]}

      , an integer value is written as double, but it should respect the order in which types have been specified.

      Fixed Code (io.py):

      def write_union(self, writers_schema, datum, encoder):
      """
      A union is encoded by first writing a long value indicating
      the zero-based position within the union of the schema of its value.
      The value is then encoded per the indicated schema within the union.
      """

      1. resolve union
        index_of_schema = -1
        for i, candidate_schema in enumerate(writers_schema.schemas):
        if validate(candidate_schema, datum):
        index_of_schema = i
        break // XXX Add break statement here XXX//
        if index_of_schema < 0: raise AvroTypeException(writers_schema, datum)

      Attachments

        1. AVRO-973-patch-1.patch
          7 kB
          Marcio Silva
        2. AVRO-973-patch-2.patch
          6 kB
          Marcio Silva
        3. AVRO-973-patch-3.patch
          6 kB
          Marcio Silva
        4. AVRO-973-wrapper.patch
          5 kB
          Douglas Kaminsky
        5. AVRO-973-wrapper.patch
          3 kB
          Douglas Kaminsky
        6. test_unions.py
          2 kB
          Marcio Silva

        Issue Links

          Activity

            People

              Unassigned Unassigned
              gaurav324 Gaurav Nanda
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0.25h
                  0.25h
                  Remaining:
                  Remaining Estimate - 0.25h
                  0.25h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified