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

BytesRefArrayWritable compareTo violates contract

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.11.0, 0.12.0
    • 0.13.0
    • None

    Description

      BytesRefArrayWritable's compareTo violates the compareTo contract from java.lang.Object. Specifically:

      • The implementor must ensure sgn(x.compareTo( y )) == -sgn(y.compareTo( x )) for all x and y.

      The compareTo implementation on BytesRefArrayWritable does a proper comparison of the sizes of the two instances. However, if the sizes are the same, it proceeds to do a check if both array's have the same constant. If not, it returns 1. This means that if x and y are two BytesRefArrayWritable instances with the same size, but different contents, then x.compareTo( y ) == 1 and y.compareTo( x ) == 1.

      Additionally, the comparison of contents is order agnostic. This seems wrong, since order of entries should matter. It is also very inefficient, running at O(n^2), where n is the number of entries.

      Attachments

        1. HIVE-5839.1.patch
          5 kB
          Xuefu Zhang
        2. HIVE-5839.2.patch
          3 kB
          Xuefu Zhang
        3. HIVE-5839.patch
          0.8 kB
          Xuefu Zhang
        4. HIVE-5839.patch
          0.8 kB
          Xuefu Zhang

        Activity

          People

            xuefuz Xuefu Zhang
            nainostrebor Ian Robertson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: