SOLR-12875: AIOOBE fix when unique()/uniqueBlock() is used with DVHASH method in json.facet

This commit is contained in:
Mikhail Khludnev 2018-10-30 10:54:36 +03:00
parent ac1925045d
commit 5aa8ad5b14
4 changed files with 78 additions and 1 deletions

View File

@ -228,6 +228,9 @@ Bug Fixes
* SOLR-7557: Fix parsing of child documents using queryAndStreamResponse (Marvin Bredal Lillehaug/Stian Østerhaug via janhoy)
* SOLR-12875: fix ArrayIndexOutOfBoundsException when unique(field) or uniqueBlock(_root_) is
used with DVHASH method in json.facet. (Tim Underwood via Mikhail Khludnev)
Improvements
----------------------

View File

@ -54,6 +54,12 @@ public class UniqueBlockAgg extends UniqueAgg {
Arrays.fill(lastSeenValuesPerSlot, Integer.MIN_VALUE);
}
@Override
public void resize(Resizer resizer) {
lastSeenValuesPerSlot = resizer.resize(lastSeenValuesPerSlot, Integer.MIN_VALUE);
super.resize(resizer);
}
@Override
public Object getValue(int slot) throws IOException {
return counts[slot];

View File

@ -148,5 +148,8 @@ abstract class UniqueSlotAcc extends SlotAcc {
@Override
public void resize(Resizer resizer) {
arr = resizer.resize(arr, null);
if (counts != null) {
counts = resizer.resize(counts, 0);
}
}
}

View File

@ -2410,7 +2410,72 @@ public class TestJsonFacets extends SolrTestCaseHS {
", books2:{ buckets:[ {val:q,count:1} ] }" +
"}"
);
}
/**
* An explicit test for unique*(_root_) across all methods
*/
public void testUniquesForMethod() throws Exception {
final Client client = Client.localClient();
final SolrParams p = params("rows","0");
client.deleteByQuery("*:*", null);
SolrInputDocument parent;
parent = sdoc("id", "1", "type_s","book", "book_s","A", "v_t","q");
client.add(parent, null);
parent = sdoc("id", "2", "type_s","book", "book_s","B", "v_t","q w");
parent.addChildDocument( sdoc("id","2.1", "type_s","page", "page_s","a", "v_t","x y z") );
parent.addChildDocument( sdoc("id","2.2", "type_s","page", "page_s","b", "v_t","x y ") );
parent.addChildDocument( sdoc("id","2.3", "type_s","page", "page_s","c", "v_t"," y z" ) );
client.add(parent, null);
parent = sdoc("id", "3", "type_s","book", "book_s","C", "v_t","q w e");
parent.addChildDocument( sdoc("id","3.1", "type_s","page", "page_s","d", "v_t","x ") );
parent.addChildDocument( sdoc("id","3.2", "type_s","page", "page_s","e", "v_t"," y ") );
parent.addChildDocument( sdoc("id","3.3", "type_s","page", "page_s","f", "v_t"," z") );
client.add(parent, null);
parent = sdoc("id", "4", "type_s","book", "book_s","D", "v_t","e");
client.add(parent, null);
client.commit();
client.testJQ(params(p, "q", "type_s:page"
, "json.facet", "{" +
" types: {" +
" type:terms," +
" field:type_s," +
" limit:-1," +
" facet: {" +
" in_books: \"unique(_root_)\" }"+
" }," +
" pages: {" +
" type:terms," +
" field:page_s," +
" limit:-1," +
" facet: {" +
" in_books: \"uniqueBlock(_root_)\" }"+
" }" +
"}" )
, "response=={numFound:6,start:0,docs:[]}"
, "facets=={ count:6," +
"types:{" +
" buckets:[ {val:page, count:6, in_books:2} ]}" +
"pages:{" +
" buckets:[ " +
" {val:a, count:1, in_books:1}," +
" {val:b, count:1, in_books:1}," +
" {val:c, count:1, in_books:1}," +
" {val:d, count:1, in_books:1}," +
" {val:e, count:1, in_books:1}," +
" {val:f, count:1, in_books:1}" +
" ]}" +
"}"
);
}