Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-7111

DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

    Details

    • Lucene Fields:
      New

      Description

      It seems that the following queries return all documents, which is unexpected:

      DocValuesRangeQuery.newLongRange("dv", Long.MAX_VALUE, Long.MAX_VALUE, false, true);
      DocValuesRangeQuery.newLongRange("dv", Long.MIN_VALUE, Long.MIN_VALUE, true, false);
      

      In Solr, floats and doubles are converted to longs and -0d gets converted to Long.MIN_VALUE, and queries like {-0d TO 0d] could fail due to this, returning all documents in the index.

      1. LUCENE-7111.patch
        3 kB
        Ishan Chattopadhyaya
      2. LUCENE-7111.patch
        3 kB
        Ishan Chattopadhyaya
      3. LUCENE-7111.patch
        2 kB
        Ishan Chattopadhyaya

        Issue Links

          Activity

          Hide
          ichattopadhyaya Ishan Chattopadhyaya added a comment -

          Attaching a failing test demonstrating the problem.

          Show
          ichattopadhyaya Ishan Chattopadhyaya added a comment - Attaching a failing test demonstrating the problem.
          Hide
          ichattopadhyaya Ishan Chattopadhyaya added a comment - - edited

          Attaching an attempted fix. Not sure if there's a better way to handle this. Could someone please review?

          Edit: Never mind, the fix may not be the correct one. I'm still looking deeper. I think the fix is behaving correctly, but I am looking for suggestions from someone who knows that part of the code better.

          Show
          ichattopadhyaya Ishan Chattopadhyaya added a comment - - edited Attaching an attempted fix. Not sure if there's a better way to handle this. Could someone please review? Edit: Never mind, the fix may not be the correct one. I'm still looking deeper. I think the fix is behaving correctly, but I am looking for suggestions from someone who knows that part of the code better.
          Hide
          rcmuir Robert Muir added a comment -

          Logically i am not sure what the behavior should be... in your example min==max but minInclusive and maxInclusive "disagree".

          Show
          rcmuir Robert Muir added a comment - Logically i am not sure what the behavior should be... in your example min==max but minInclusive and maxInclusive "disagree".
          Hide
          rcmuir Robert Muir added a comment -

          and, if its an overflow in the logic that should not happen (looks like it might be), i think its worth it to change the add/subtracts here to Math.addExact/Math.subtractExact.

          Show
          rcmuir Robert Muir added a comment - and, if its an overflow in the logic that should not happen (looks like it might be), i think its worth it to change the add/subtracts here to Math.addExact/Math.subtractExact.
          Hide
          ichattopadhyaya Ishan Chattopadhyaya added a comment -

          Right Robert, I think this overflow/underflow situation should be handled more properly to guard against surprises, even if min==max but minInclusive!=maxExclusive (which I think should throw 0 results). Another way to trigger this overflow is min=Long.MAX_VALUE, max=<any value>, minInclusive=false, maxInclusive=true/false.

          Show
          ichattopadhyaya Ishan Chattopadhyaya added a comment - Right Robert, I think this overflow/underflow situation should be handled more properly to guard against surprises, even if min==max but minInclusive!=maxExclusive (which I think should throw 0 results). Another way to trigger this overflow is min=Long.MAX_VALUE, max=<any value>, minInclusive=false, maxInclusive=true/false.
          Hide
          yseeley@gmail.com Yonik Seeley added a comment -

          I think this overflow/underflow situation should be handled more properly to guard against surprises

          +1, patch looks good.

          Show
          yseeley@gmail.com Yonik Seeley added a comment - I think this overflow/underflow situation should be handled more properly to guard against surprises +1, patch looks good.
          Hide
          jpountz Adrien Grand added a comment -

          +1 to the patch

          Show
          jpountz Adrien Grand added a comment - +1 to the patch
          Hide
          steve_rowe Steve Rowe added a comment -

          +1 to the patch.

          Show
          steve_rowe Steve Rowe added a comment - +1 to the patch.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 751a53fe00a4dc02f579d0e4356c2198dbdd7228 in lucene-solr's branch refs/heads/master from Steve Rowe
          [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=751a53f ]

          LUCENE-7111: DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

          Show
          jira-bot ASF subversion and git services added a comment - Commit 751a53fe00a4dc02f579d0e4356c2198dbdd7228 in lucene-solr's branch refs/heads/master from Steve Rowe [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=751a53f ] LUCENE-7111 : DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 4148cdf7446dca03e59cd5662f49b8286b3ba856 in lucene-solr's branch refs/heads/branch_6x from Steve Rowe
          [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=4148cdf ]

          LUCENE-7111: DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

          Show
          jira-bot ASF subversion and git services added a comment - Commit 4148cdf7446dca03e59cd5662f49b8286b3ba856 in lucene-solr's branch refs/heads/branch_6x from Steve Rowe [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=4148cdf ] LUCENE-7111 : DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 1201524d8ff24727993a8d3949d783d5a947221a in lucene-solr's branch refs/heads/branch_6_0 from Steve Rowe
          [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=1201524 ]

          LUCENE-7111: DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

          Show
          jira-bot ASF subversion and git services added a comment - Commit 1201524d8ff24727993a8d3949d783d5a947221a in lucene-solr's branch refs/heads/branch_6_0 from Steve Rowe [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=1201524 ] LUCENE-7111 : DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE
          Hide
          steve_rowe Steve Rowe added a comment -

          Thanks Ishan!

          Show
          steve_rowe Steve Rowe added a comment - Thanks Ishan!
          Hide
          hossman Hoss Man added a comment -

          Manually correcting fixVersion per Step #S5 of LUCENE-7271

          Show
          hossman Hoss Man added a comment - Manually correcting fixVersion per Step #S5 of LUCENE-7271
          Hide
          steve_rowe Steve Rowe added a comment -

          Reopening to backport to 5.6 and 5.5.2.

          Show
          steve_rowe Steve Rowe added a comment - Reopening to backport to 5.6 and 5.5.2.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 52d41a1368b7ee36375df0099ccc2042ec5cf642 in lucene-solr's branch refs/heads/branch_5_5 from Steve Rowe
          [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=52d41a1 ]

          LUCENE-7111: DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

          Show
          jira-bot ASF subversion and git services added a comment - Commit 52d41a1368b7ee36375df0099ccc2042ec5cf642 in lucene-solr's branch refs/heads/branch_5_5 from Steve Rowe [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=52d41a1 ] LUCENE-7111 : DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit c541d59f8dc19a174059214874b0d212832c2498 in lucene-solr's branch refs/heads/branch_5x from Steve Rowe
          [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=c541d59 ]

          LUCENE-7111: DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

          Show
          jira-bot ASF subversion and git services added a comment - Commit c541d59f8dc19a174059214874b0d212832c2498 in lucene-solr's branch refs/heads/branch_5x from Steve Rowe [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=c541d59 ] LUCENE-7111 : DocValuesRangeQuery.newLongRange behaves incorrectly for Long.MAX_VALUE and Long.MIN_VALUE

            People

            • Assignee:
              steve_rowe Steve Rowe
              Reporter:
              ichattopadhyaya Ishan Chattopadhyaya
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development