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

Hive does not treat floating point signed zeros as equal (-0.0 should equal 0.0 according to IEEE floating point spec)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.2.0
    • 2.0.0
    • Query Processor
    • None

    Description

      Hive does not treat floating point signed zeros as equal (-0.0 should equal 0.0). This is because Hive uses Double.compareTo(), which states (http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#compareTo(java.lang.Double):

      0.0d is considered by this method to be greater than -0.0d

      The IEEE 754 floating point spec specifies that signed -0.0 and 0.0 should be treated as equal. From the Wikipedia article (https://en.wikipedia.org/wiki/Signed_zero#Comparisons):

      negative zero and positive zero should compare as equal with the usual (numerical) comparison operators

      Java's compareTo method is implemented to allow for ordering of object instances (in a hash table or similar), but Hive should abide by the IEEE spec.

      How to reproduce:

      select 1 where 0.0=-0.0;
      Returns no results.
      
      select 1 where -0.0<0.0;
      Returns 1
      

      Attachments

        1. HIVE-11174.1.patch
          3 kB
          Sergio Peña

        Issue Links

          Activity

            People

              spena Sergio Peña
              lskuff Lenni Kuff
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: