Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-8940

group.sort broken, can through AIOOBE if clause length differs from sort param, or cast exception if datatypes are incompatible with sort clause types

    Details

      Description

      We get an ArrayIndexOutOfBoundsException when searching after upgrading to solr 5.5.

      Here's the query:

      "params":{
            "q":"*:*",
            "group.sort":"priceAmount asc,rnd desc",
            "indent":"on",
            "fl":"priceAmount,flightTripId,brand,slob,cabinType,tripDuration",
            "group.limit":"100",
            "fq":["searchId:e31a0c58-9056-4297-8d70-049017ba4906",
              "doctype:offer",
              "flightTripId:(DY6020421-SK2360519 OR DY6020421-SK2600519 OR DY6020421-SK2620519 OR DY6020421-SK2740519 OR DY6020421-SK2900519 OR DY6020421-SK2860519 OR DY6040421-SK2380519 OR DY6040421-SK2440519 OR DY6040421-SK2480519 OR DY6040421-SK2520519 OR DY6040421-SK2600519 OR DY6040421-SK2620519 OR DY6040421-SK2720519 OR DY6040421-SK2740519 OR DY6040421-SK2800519 OR DY6040421-SK2840519 OR DY6040421-SK2820519 OR DY6060421-SK2480519 OR DY6060421-SK2740519 OR DY6060421-SK2800519 OR DY6060421-SK2840519 OR DY6060421-SK2900519 OR DY6060421-SK2860519 OR DY6060421-SK2820519 OR DY6080421-SK2440519)",
              "maximumLegDuration:[* TO 180]",
              "departureAirportLeg1:(OSL)",
              "(arrivalAirportLeg2:(OSL) OR (* NOT arrivalAirportLeg2:*))",
              "arrivalAirportLeg1:(BGO)",
              "(departureAirportLeg2:(BGO) OR (* NOT departureAirportLeg2:*))"],
            "group.ngroups":"true",
            "wt":"json",
            "group.field":"flightTripId",
            "group":"true"}}
      

      And here's the exception:

      ERROR [20160404T104846,333] qtp315138752-3037 org.apache.solr.servlet.HttpSolrCall - null:java.lang.ArrayIndexOutOfBoundsException: 1
              at org.apache.solr.search.grouping.distributed.shardresultserializer.TopGroupsResultTransformer.transformToNativeShardDoc(TopGroupsResultTransformer.java:175)
              at org.apache.solr.search.grouping.distributed.shardresultserializer.TopGroupsResultTransformer.transformToNative(TopGroupsResultTransformer.java:137)
              at org.apache.solr.search.grouping.distributed.responseprocessor.TopGroupsShardResponseProcessor.process(TopGroupsShardResponseProcessor.java:129)
              at org.apache.solr.handler.component.QueryComponent.handleGroupedResponses(QueryComponent.java:750)
              at org.apache.solr.handler.component.QueryComponent.handleResponses(QueryComponent.java:733)
              at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:405)
              at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:155)
              at org.apache.solr.core.SolrCore.execute(SolrCore.java:2082)
      

      The exception is thrown at the last line here (TopGroupsResultTransformer.java line 175):

        protected ScoreDoc[] transformToNativeShardDoc(List<NamedList<Object>> documents, Sort groupSort, String shard,
                                                       IndexSchema schema) {
          [...]
          for (NamedList<Object> document : documents) {
            [...]
            Object sortValuesVal = document.get("sortValues");
            if (sortValuesVal != null) {
              sortValues = ((List) sortValuesVal).toArray();
              for (int k = 0; k < sortValues.length; k++) {
                SchemaField field = groupSort.getSort()[k].getField() != null
                    ? schema.getFieldOrNull(groupSort.getSort()[k].getField()) : null;
      

      It's not obvious to me that sortValues.length == groupSort.getSort().length, but I guess there's some logic behind it

      I have attached the schema and json result.

      The problem disappears when rolling back to 5.4.0.

        Attachments

        1. solr-query-exception.txt
          4 kB
          Henrik
        2. schema-types.xml
          0.6 kB
          Henrik
        3. schema.xml
          5 kB
          Henrik
        4. solrconfig.xml
          5 kB
          Henrik
        5. 0001-SOLR-8940-Avoid-ArrayIndexOutOfBoundsException-in-To.patch
          2 kB
          Henrik
        6. SOLR-8940.patch
          4 kB
          Hoss Man

          Issue Links

            Activity

              People

              • Assignee:
                hossman Hoss Man
                Reporter:
                monti Henrik
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: