SOLR-13206: Fix AIOOBE when group.facet is specified with group.query

group.facet is supported only for group.field. When group.facet is
used with group.query, then return proper error code
This commit is contained in:
Munendra S N 2019-07-18 10:54:57 +05:30
parent 0de627ee26
commit 1fc416404c
3 changed files with 41 additions and 1 deletions

View File

@ -81,6 +81,11 @@ Improvements
* SOLR-12368: Support InPlace DV updates for a field that does not yet exist in any documents * SOLR-12368: Support InPlace DV updates for a field that does not yet exist in any documents
(hossman, Simon Willnauer, Adrien Grand, Munendra S N) (hossman, Simon Willnauer, Adrien Grand, Munendra S N)
Bug Fixes
----------------------
* SOLR-13206: Fix AIOOBE when group.facet is specified with group.query and return proper error code. (Marek, Munendra S N)
================== 8.2.0 ================== ================== 8.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -38,6 +38,7 @@ import java.util.concurrent.Semaphore;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.lucene.index.ExitableDirectoryReader; import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
@ -705,7 +706,8 @@ public class SimpleFacets {
String prefix, String prefix,
Predicate<BytesRef> termFilter) throws IOException { Predicate<BytesRef> termFilter) throws IOException {
GroupingSpecification groupingSpecification = rb.getGroupingSpec(); GroupingSpecification groupingSpecification = rb.getGroupingSpec();
final String groupField = groupingSpecification != null ? groupingSpecification.getFields()[0] : null; String[] groupFields = groupingSpecification != null? groupingSpecification.getFields(): null;
final String groupField = ArrayUtils.isNotEmpty(groupFields) ? groupFields[0] : null;
if (groupField == null) { if (groupField == null) {
throw new SolrException ( throw new SolrException (
SolrException.ErrorCode.BAD_REQUEST, SolrException.ErrorCode.BAD_REQUEST,

View File

@ -3303,6 +3303,39 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
); );
} }
public void testGroupFacetErrors() {
ModifiableSolrParams params = params("q", "*:*", "group", "true", "group.query", "myfield_s:*",
"facet", "true", "group.facet", "true");
// with facet.field
SolrException ex = expectThrows(SolrException.class, () -> {
h.query(req(params, "facet.field", "myfield_s"));
});
assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
// with facet.query
ex = expectThrows(SolrException.class, () -> {
h.query(req(params, "facet.query", "myfield_s:*"));
});
assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
// with facet.range
ex = expectThrows(SolrException.class, () -> h.query(req(params, "facet.range", "range_facet_l",
"facet.range.start", "43", "facet.range.end", "450", "facet.range.gap", "10"))
);
assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
// with facet.interval
ex = expectThrows(SolrException.class, () -> h.query(req(params, "facet.interval", "range_facet_l",
"f.range_facet_l.facet.interval.set", "(43,60]"))
);
assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
assertTrue(ex.getMessage().contains("Interval Faceting can't be used with group.facet"));
}
public void testRangeFacetingBadRequest() { public void testRangeFacetingBadRequest() {
String field = "range_facet_l"; String field = "range_facet_l";