You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2022/04/04 19:03:00 UTC

[jira] [Commented] (LUCENE-10466) IndexSortSortedNumericDocValuesRangeQuery unconditionally assumes the usage of the LONG-encoded SortField

    [ https://issues.apache.org/jira/browse/LUCENE-10466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17517047#comment-17517047 ] 

ASF subversion and git services commented on LUCENE-10466:
----------------------------------------------------------

Commit 737ce42c1c0a8697009b97d72386f2c165d07add in lucene's branch refs/heads/main from Andriy Redko
[ https://gitbox.apache.org/repos/asf?p=lucene.git;h=737ce42c1c0 ]

LUCENE-10466: Ensure IndexSortSortedNumericDocValuesRangeQuery handles sort types besides LONG

IndexSortSortedNumericDocValuesRangeQuery unconditionally assumes the usage of
the LONG-encoded SortField. Using the numeric range query (in case of sorted
index) with anything but LONG ends up with class cast exception. Now the query
consults the numeric type of the `SortField` and perform appropriate checks.

> IndexSortSortedNumericDocValuesRangeQuery unconditionally assumes the usage of the LONG-encoded SortField
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-10466
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10466
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/query/scoring
>    Affects Versions: 9.0
>            Reporter: Andriy Redko
>            Priority: Minor
>          Time Spent: 5.5h
>  Remaining Estimate: 0h
>
> We have run into this issue while migrating to OpenSearch and making changes to accommodate https://issues.apache.org/jira/browse/LUCENE-10087. It turned out that *IndexSortSortedNumericDocValuesRangeQuery* unconditionally assumes the usage of the LONG-encoded {*}SortField{*}, as could be seen inside *static ValueComparator loadComparator* method
> {noformat}
>     @SuppressWarnings("unchecked")
>     FieldComparator<Long> fieldComparator = (FieldComparator<Long>) sortField.getComparator(1, 0);
>     fieldComparator.setTopValue(topValue);
>  {noformat}
>  
> Using the numeric range query (in case of sorted index) with anything but LONG ends up with class cast exception:
> {noformat}
>    >     java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
>    >         at org.apache.lucene.search.comparators.IntComparator.setTopValue(IntComparator.java:29)
>    >         at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery.loadComparator(IndexSortSortedNumericDocValuesRangeQuery.java:251)
>    >         at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery.getDocIdSetIterator(IndexSortSortedNumericDocValuesRangeQuery.java:206)
>    >         at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery$1.scorer(IndexSortSortedNumericDocValuesRangeQuery.java:170)
>  {noformat}
> Simple test case to reproduce (for TestIndexSortSortedNumericDocValuesRangeQuery):
> {noformat}
>   public void testIndexSortDocValuesWithIntRange() throws Exception {
>     Directory dir = newDirectory();    
>     IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
>     Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.INT, false));
>     iwc.setIndexSort(indexSort);
>     
>     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);    
>     writer.addDocument(createDocument("field", -80));    
>     
>     DirectoryReader reader = writer.getReader();
>     IndexSearcher searcher = newSearcher(reader);    // Test ranges consisting of one value.
>     assertEquals(1, searcher.count(createQuery("field", -80, -80)));    
>     writer.close();
>     reader.close();
>     dir.close();
>   } {noformat}
>  
> The expectation is that *IndexSortSortedNumericDocValuesRangeQuery* should not fail with class cast but correctly convert the numeric values.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org