Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-5176

KeyRange.compareUpperRange(KeyRang 1, KeyRang 2) returns wrong result when two key ranges have the same upper bound values but one is inclusive and another is exclusive

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 4.15.0, 5.1.0
    • None
    • None

    Description

      In KeyRange.java, 
          public static int compareUpperRange(KeyRange rowKeyRange1, KeyRange rowKeyRange2) {
              int result = Boolean.compare(rowKeyRange1.upperUnbound(), rowKeyRange2.upperUnbound());
              if (result != 0) {
                  return result;
              }
              result = Bytes.BYTES_COMPARATOR.compare(rowKeyRange1.getUpperRange(), rowKeyRange2.getUpperRange());
              if (result != 0) {
                  return result;
              }
              return Boolean.compare(rowKeyRange2.isUpperInclusive(), rowKeyRange1.isUpperInclusive());
          }
       
      The last line in yellow color should be "return Boolean.compare(rowKeyRange1.isUpperInclusive(), rowKeyRange2.isUpperInclusive());".  Given rowKeyRange1 [3, 5) and rowKeyRange2 [3, 5], the function should return -1, but now it returns 1 due to the bug I mentioned.
       
      The KeyRange.compareUpperRange is only used in KeyRange.intersect(List<KeyRange> rowKeyRanges1, List<KeyRange> rowKeyRanges2). Given rowKeyRanges1 {[3, 5), [5, 6)} and rowKeyRanges2{[3, 5], [6, 7]}, the function should return {[3, 5), [5, 5]}, i.e., {[3, 5]}, but it seems that now it returns {[3,5)} due to the bug.

      Attachments

        Issue Links

          Activity

            People

              Bin Shi Bin Shi
              Bin Shi Bin Shi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4h
                  4h