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

SpecificRecord doesn't check for equality correctly with respect to maps

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.7.0, 1.7.1
    • 1.7.2
    • None
    • None

    Description

      In Java, map equality is based on the contents of a map rather than ordering, since order is undefined in the plain Java map implementation. The present implementation of SpecificRecord relies on SpecificData's public compare() method, which doesn't expose any method to relax the ordering requirement for maps (a protected-visibility implementation exists that does). Since specificRecord is based on map (and not some sort of ordered map) the current implementation with respect to the Java spec is fundamentally incompatible since Java doesn't require a notion of ordering for the Map interface and Avro can.

      There's a few ways this could be solved:

      1. Require Avro Java to use the LinkedHashMap implementation of map (or similar) so that map ordering can be compared and not break the normal expectations of a java developer. This is problematic because it dramatically restricts the API and forces an implementation of Map that is undesirable under some circumstances. Unfortunately there is no concept of OrderedMap in Java, just SortedMap.
      2. Change SpecificData to compare maps based on contents (set equals=true when recursively comparing maps)
      3. Change the visibility of SpecificData.compare(SpecificRecord,SpecificRecord,boolean) to public and change SpecificRecord.equals(Object) to compare only on equality rather than order.

      Attachments

        1. AVRO-1128.patch
          1 kB
          Doug Cutting

        Activity

          People

            cutting Doug Cutting
            ekohlwey Ed Kohlwey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: