Jackie-Jiang commented on PR #14958:
URL: https://github.com/apache/pinot/pull/14958#issuecomment-2626528318

   > Maybe the fix should be where we set `isSorted`? Meaning when we're 
iterating values checking if it's sorted, we should check that both `.equals` 
and `.compareTo` return (`true` and `0`) or (`false` and `1/-1`). Otherwise, 
the index just can't properly handle it.
   
   Sorted index is just one structure that can be broken because the ordering 
is not consistent with equals. Other data structure such as `TreeMap` could 
also break, and you may read more about that in the javadoc of `Comparable` 
interface.
   
   This part is interesting, which literally explains this problem:
   ```
    * It is strongly recommended (though not required) that natural orderings be
    * consistent with equals.  This is so because sorted sets (and sorted maps)
    * without explicit comparators behave "strangely" when they are used with
    * elements (or keys) whose natural ordering is inconsistent with equals.  In
    * particular, such a sorted set (or sorted map) violates the general 
contract
    * for set (or map), which is defined in terms of the {@code equals}
    * method.<p>
    *
    * For example, if one adds two keys {@code a} and {@code b} such that
    * {@code (!a.equals(b) && a.compareTo(b) == 0)} to a sorted
    * set that does not use an explicit comparator, the second {@code add}
    * operation returns false (and the size of the sorted set does not increase)
    * because {@code a} and {@code b} are equivalent from the sorted set's
    * perspective.<p>
    *
    * Virtually all Java core classes that implement {@code Comparable} have 
natural
    * orderings that are consistent with equals.  One exception is
    * {@code java.math.BigDecimal}, whose natural ordering equates
    * {@code BigDecimal} objects with equal values and different precisions
    * (such as 4.0 and 4.00).<p>
   ```
   
   I don't think we can handle this in all places


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to