Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-10621

serde typeinfo equals methods are not symmetric

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Pending Closed
    • None
    • 1.3.0
    • None

    Description

      correct equals method implementation should start with

        if (this == other) {
          return true;
        }
        if (other == null || getClass() != other.getClass()) {
          return false;
        }
      

      DecimalTypeInfo, PrimitiveTypeInfo, VarcharTypeInfo, CharTypeInfo, HiveDecimalWritable equals method implementation starts with

        if (other == null || !(other instanceof <class_name>)) {
          return false
        }
      
      • first of all check for null is redundant
      • the second issue is that "other instanceof <class_name>" check is not symmetric.

      contract of equals() implies that, a.equals(b) is true if and only if b.equals(a) is true
      Current implementation violates this contract.
      e.g.
      DecimalTypeInfo instanceof PrimitiveTypeInfo is true
      but
      PrimitiveTypeInfo instanceof DecimalTypeInfo is false

      See more details here http://stackoverflow.com/questions/6518534/equals-method-overrides-equals-in-superclass-and-may-not-be-symmetric

      Attachments

        1. rb33880.patch
          4 kB
          Alexander Pivovarov
        2. HIVE-10621.1.patch
          4 kB
          Alexander Pivovarov

        Activity

          People

            apivovarov Alexander Pivovarov
            apivovarov Alexander Pivovarov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: